复合类型

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

  • 复制
    复制成功
postgres=# CREATE TYPE public.t_per AS
(
    id integer,
    mc text
);
CREATE TYPE
postgres=# CREATE OR REPLACE PROCEDURE p_type (a_row public.t_per) AS                               
$$
BEGIN          
    RAISE NOTICE 'id = % ; mc = %',a_row.id,a_row.mc;
END;
$$
LANGUAGE PLPGSQL;
CREATE PROCEDURE
postgres=# CALL p_type(ROW(1,'TBase')::public.t_per);
NOTICE:  id = 1 ; mc = TBase
CALL
postgres=#
  • 复合数组。
  • 复制
    复制成功
postgres=# CREATE OR REPLACE PROCEDURE p_type_array (a_rec public.t_per[]) AS
$$
BEGIN
    RAISE NOTICE 'a_rec = %',a_rec;
    RAISE NOTICE 'a_rec[1].id = %',a_rec[1].id;
END;
$$
LANGUAGE PLPGSQL;
CREATE PROCEDURE
postgres=# CALL p_type_array (ARRAY[ROW(1,'TBase'),ROW(1,'pgxz')]::public.t_per[]);
NOTICE:  a_rec = {"(1,TBase)","(1,pgxz)"}
NOTICE:  a_rec[1].id = 1
CALL
postgres=#