如何解决如何将查询加载到复合类型数组中?
我有一个包含 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 的数组并显示在输出中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。