我喜欢用 xpaht 查询 数据库 :
安装 :
wget
编译准备:
sudo apt-get install libxml2-dev
pl/perl
我这在 make all 时出错 :重新编译 个perl 到 /opt/perl5
并且在 make all 失败后再编译 下面语句
> gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -fpic -shared -o plperl.so plperl.o SPI.o Util.o -L../../../src/port -Wl,--as-needed -Wl,-rpath,'/opt/perl5/lib/5.12.2/i686-linux/CORE',--enable-new-dtags -L/usr/local/lib -L/usr/lib/perl/5.10/CORE -ldl -lm -lpthread -lc -lcrypt
> make install
正式编译 :
./configure --with-perl --with-python --with-libxml
gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
createlang plperl test
参考 :
/usr/local/pgsql/bin/psql test
> SELECT xmlcomment('hello');
> CREATE TABLE test2 ( id int PRIMARY KEY,xdoc xml);
> INSERT INTO test VALUES (2, '');
> INSERT INTO test VALUES (1, '歌曲1');
> update test set xdoc=xmlconcat(xdoc,'歌曲1_ID') where id=1;
> INSERT INTO test VALUES (3, '歌曲2歌曲2_ID');
> select xmlagg(xdoc) from test where id<>2;
xmlagg
----------------------------------------------------------------------------
歌曲1歌曲1_ID歌曲2歌曲2_ID
> select xmlelement(name music,xdoc) from test where id<>2;
xmlelement
------------------------------------------------------
歌曲1歌曲1_ID
歌曲2歌曲2_ID
(2 rows)
> select
xpath('//pmn/text()',
xmlelement( name musics,
xmlagg( xmlelement(name music,xdoc) )
)
)
from test where id<>2;
xpath
---------------
{歌曲1,歌曲2}
阅读(849) | 评论(1) | 转发(0) |