Chinaunix首页 | 论坛 | 博客
  • 博客访问: 629587
  • 博文数量: 149
  • 博客积分: 3901
  • 博客等级: 中校
  • 技术积分: 1558
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-16 14:33
文章分类

全部博文(149)

文章存档

2014年(2)

2013年(10)

2012年(32)

2011年(21)

2010年(84)

分类:

2010-09-28 10:03:40

我喜欢用 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}



阅读(804) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-28 15:34:03

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com