行类型

最近更新时间: 2025-02-18 16:02:00

  • 复制
    复制成功
postgres=# \d t
    资料表 "public.t"
 栏位 |  型别   | 修饰词
------+---------+--------
 id   | integer |
 mc   | text    |
postgres=# CREATE OR REPLACE FUNCTION f3 (a_row public.t) RETURNS VOID AS
postgres-# $$
postgres$# BEGIN
postgres$#     RAISE NOTICE 'id = % ; mc = %',a_row.id,a_row.mc;
postgres$# END;
postgres$# $$
postgres-# LANGUAGE PLPGSQL;
CREATE FUNCTION
postgres=#
postgres=# SELECT f3(ROW(1,'TDSQL PG'));
NOTICE:  id = 1 ; mc = TDSQL PG
 f3
----
(1 行记录)
postgres=# SELECT f3(t.*) FROM t LIMIT 1;
NOTICE:  id = 1 ; mc = TDSQL PG
 f3
----
(1 行记录)
postgres=# CREATE OR REPLACE FUNCTION f3 (a_rec public.t[]) RETURNS VOID AS
postgres-# $$
postgres$# BEGIN
postgres$#     RAISE NOTICE 'a_rec = %',a_rec;
postgres$#     RAISE NOTICE 'a_rec[1].id = %',a_rec[1].id;
postgres$# END;
postgres$# $$
postgres-# LANGUAGE PLPGSQL;
CREATE FUNCTION
postgres=#
postgres=# SELECT f3(array[row(1,'TDSQL PG'),row(1,'pgxz')]::public.t[]);
NOTICE:  a_rec = {"(1,TDSQL PG)","(1,pgxz)"}
NOTICE:  a_rec[1].id = 1
 f3
----
(1 行记录)
postgres=# SELECT f3(array[t.*,t.*]::public.t[]) FROM t LIMIT 2;
NOTICE:  a_rec = {"(1,TDSQL PG)","(1,TDSQL PG)"}
NOTICE:  a_rec[1].id = 1
NOTICE:  a_rec = {"(2,pgxz)","(2,pgxz)"}
NOTICE:  a_rec[1].id = 2
 f3
----
(2 行记录)