复合类型

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

  • 复制
    复制成功
postgres=# CREATE TYPE t_per AS
postgres-# (
postgres(#     id integer,
postgres(#     mc text
postgres(# );
ERROR:  type "t_per" already exists
postgres=# CREATE OR REPLACE FUNCTION f3 (a_row public.t_per) 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')::public.t_per);
NOTICE:  id = 1 ; mc = TDSQL PG
 f3
----
(1 行记录)
postgres=# CREATE OR REPLACE FUNCTION f3 (a_rec public.t_per[]) 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_per[]);
NOTICE:  a_rec = {"(1,TDSQL PG)","(1,pgxz)"}
NOTICE:  a_rec[1].id = 1
 f3
----
(1 行记录)