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

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/

你可能感兴趣的:(PostgreSQL函数里调用函数(SETOF + RETURN QUERY))