您的位置:首页 > 产品设计 > UI/UE

PostgreSQL函数里调用函数(SETOF + RETURN QUERY)

2018-12-07 10:45 465 查看

PostgreSQL函数里调用函数(SETOF + RETURN QUERY)


1、函数如下:
CREATE OR REPLACE FUNCTION public.get_version() RETURNS SETOF text AS
$$
BEGIN
     RETURN query select version();
END
$$
language plpgsql;


2、实验记录:
postgres=# CREATE OR REPLACE FUNCTION public.get_version() RETURNS SETOF text AS
postgres-# $$
postgres$# BEGIN
postgres$#     RETURN query select * from version();
postgres$# END
postgres$# $$
postgres-# language plpgsql;
CREATE FUNCTION
postgres=#
postgres=#
postgres=# select get_version();
                                               get_version                                              
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)

postgres=# select version();
                                                 version                                                
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)

postgres=# select * from version();
                                                 version                                                
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)

postgres=#
postgres=#
postgres=# CREATE OR REPLACE FUNCTION public.get_version1() RETURNS SETOF text AS
postgres-# $$
postgres$# BEGIN
postgres$#     RETURN query select version();
postgres$# END
postgres$# $$
postgres-# language plpgsql;
CREATE FUNCTION
postgres=# select get_version1();
                                              get_version1                                              
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)

postgres=# select * from get_version1();
                                              get_version1                                              
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)

postgres=#

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27126919/viewspace-2284475/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27126919/viewspace-2284475/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
-->
新的分享
章节导航