如何将查询加载到复合类型数组中?
How to load a query into composite type array?
我有一个包含 3 列和多行的查询。我需要将查询结果存储到复合类型的数组中。有人可以帮助如何使用 array_agg 或其他方法而不是使用循环来实现它吗?
CREATE TYPE type1 AS
(
id bigint,
name character varying(4000),
created_on date
);
do
$$
declare
arr_type1 type1[];
--Query is select st_id, st_name, recorded_dt from st_samples;
end;
$$
language plpgsql;
我需要将上述注释查询中的数据加载到 arr_type1
数组中。提前致谢。
这可能是您要找的:
do $$
declare
t type1[];
begin
select array_agg(row(id,name,recorded_dt)::type1) into t from st_samples;
raise notice '%',t;
end;
$$
没有做任何有成效的事情,但 t 包含 type1 的数组并显示在输出中。
我有一个包含 3 列和多行的查询。我需要将查询结果存储到复合类型的数组中。有人可以帮助如何使用 array_agg 或其他方法而不是使用循环来实现它吗?
CREATE TYPE type1 AS
(
id bigint,
name character varying(4000),
created_on date
);
do
$$
declare
arr_type1 type1[];
--Query is select st_id, st_name, recorded_dt from st_samples;
end;
$$
language plpgsql;
我需要将上述注释查询中的数据加载到 arr_type1
数组中。提前致谢。
这可能是您要找的:
do $$
declare
t type1[];
begin
select array_agg(row(id,name,recorded_dt)::type1) into t from st_samples;
raise notice '%',t;
end;
$$
没有做任何有成效的事情,但 t 包含 type1 的数组并显示在输出中。