文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Extending the Database: PL/pgSQL

Extending the Database: PL/pgSQL

时间:2010-01-23  来源:admin126com

Extending the Database: PL/pgSQL

* PostgreSQL offers two interpreted languages in which one can write SQL functions: PL/pgSQL and PL/tcl. More can be added by the user by coding the appropriate stub.

* PL/pgSQL Example:

As user postgres:

test=> CREATE FUNCTION plpgsql_call_handler () 
test-> RETURNS OPAQUE
test-> AS '/usr/lib/pgsql/plpgsql.so'
test-> LANGUAGE 'c' \g
CREATE
test=>
test=> CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
test-> HANDLER plpgsql_call_handler
test-> LANCOMPILER 'PL/pgSQL' \g
CREATE

As user shlomi:

test=> CREATE FUNCTION num_descendants (int4)
test-> RETURNS int4 AS
test-> '
test'>     DECLARE
test'>         key ALIAS for $1;
test'>         num int4;
test'>         child RECORD;
test'>     BEGIN
test'>         num := 0;
test'>         FOR child IN SELECT c FROM par_kids WHERE p = key LOOP
test'>             num := num + 1 + num_descendants(child.c);
test'>         END LOOP;
test'>         RETURN num;
test'>     END;
test'> '
test-> LANGUAGE 'plpgsql' \g
CREATE
test=> SELECT num_descendants(1) \g
num_descendants
---------------
              9
(1 row)
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载