对PostgreSQL SPI例子的学习
生活随笔
收集整理的這篇文章主要介紹了
对PostgreSQL SPI例子的学习
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
[作者:技術(shù)者高健@博客園 ?mail:?luckyjackgao@gmail.com?]
http://www.postgresql.org/docs/9.1/static/spi-examples.html
?
SPI 的例子里面沒有說,是如何編譯和部署的,我這里補(bǔ)充下:
編譯與部署:
[root@localhost soft]# export LD_LIBRARY_PATH=/usr/local/pgsql/lib [root@localhost soft]# echo $LD_LIBRARY_PATH /usr/local/pgsql/lib[root@localhost test]# cc -fpic -I/usr/local/pgsql/include/server/ -shared -o execq.so execq.c [root@localhost test]# ls execq.c execq.so [root@localhost test]# [root@localhost test]# cp execq.so /usr/local/pgsql/lib [root@localhost test]#運(yùn)行:
postgres=# create function execq(text,integer) returns integer as '/usr/local/pgsql/lib/execq.so','execq' language c strict; CREATE FUNCTION postgres=# postgres=# select execq('create table abc(id integer)',0);execq ------- 0 (1 row)postgres=# postgres=# insert into abc values( execq('insert into abc values(0)',0)); INSERT 0 1 postgres=# postgres=# insert into abc values( execq('insert into abc values(0)',0)); INSERT 0 1 postgres=# select * from abc;id ---- 0 1 (2 rows)postgres=# postgres=# select execq('select * from abc',0); INFO: EXECQ: 0 INFO: EXECQ: 1 execq ------- 2 (1 row)postgres=# postgres=# select execq('insert into abc select id+2 from abc',1);execq ------- 2 (1 row)postgres=# select * from abc;id ---- 0 1 2 3 (4 rows)postgres=# postgres=# select execq('select * from abc', 10); INFO: EXECQ: 0 INFO: EXECQ: 1 INFO: EXECQ: 2 INFO: EXECQ: 3 execq ------- 4 (1 row)postgres=#[作者:技術(shù)者高健@博客園 ?mail:?luckyjackgao@gmail.com?]
?
轉(zhuǎn)載于:https://www.cnblogs.com/gaojian/archive/2012/10/29/2744195.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的对PostgreSQL SPI例子的学习的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员需要了解的一点组织行为学知识
- 下一篇: 【Python】Python中对目录路径