ITPub博客

首页 > 数据库 > PostgreSQL > PostgreSQL函数里调用函数(SETOF + RETURN QUERY)

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

原创 PostgreSQL 作者:shytodear 时间:2018-12-07 10:45:22 0 删除 编辑

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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-11-05

  • 博文量
    65
  • 访问量
    164485