返回一个复合类型
最近更新时间: 2025-02-18 16:02:00
postgres=# CREATE TYPE t_rec AS
postgres-# (
postgres(# id integer,
postgres(# mc text
postgres(# );
CREATE TYPE
postgres=#
postgres=# CREATE OR REPLACE FUNCTION f11() RETURNS t_rec AS
postgres-# $$
postgres$# DECLARE
postgres$# v_rec public.t_rec;
postgres$# BEGIN
postgres$# v_rec.id:=1;
postgres$# v_rec.mc='TDSQL PG';
postgres$# RETURN v_rec;
postgres$# END;
postgres$# $$
postgres-# LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# SELECT * FROM f11();
id | mc
----+------
1 | TDSQL PG
(1 行记录)
postgres=# CREATE OR REPLACE FUNCTION f12() RETURNS t_rec[] AS
postgres-# $$
postgres$# BEGIN
postgres$# RETURN ARRAY[ROW(1,'TDSQL PG'),ROW(1,'pgxz')]::t_rec[];
postgres$# END;
postgres$# $$
postgres-# LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# SELECT * FROM f12();
f12
---------------------------
{"(1,TDSQL PG)","(1,pgxz)"}
(1 行记录)