欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

对PostgreSQL SPI例子的学习

发布时间:2023/12/2 58 豆豆
生活随笔 收集整理的这篇文章主要介绍了 对PostgreSQL SPI例子的学习 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

http://www.postgresql.org/docs/9.1/static/spi-examples.html

 

SPI 的例子里面没有说,是如何编译和部署的,我这里补充下:

编译与部署:

[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]#

运行:

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=#

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

 

转载于:https://www.cnblogs.com/gaojian/archive/2012/10/29/2744195.html

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的对PostgreSQL SPI例子的学习的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。