zoukankan      html  css  js  c++  java
  • 对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 ]

     

  • 相关阅读:
    使用KNN算法手写体识别
    os内置模块
    python步长为负时的情况
    qplot()函数的详细用法
    python文件I/O
    python中 @property
    python中定制类
    python中多重继承与获取对象
    python继承,判断类型,多态
    python中访问限制
  • 原文地址:https://www.cnblogs.com/gaojian/p/2744195.html
Copyright © 2011-2022 走看看