我想制作一个数组并将两个id放入其中,但是我遇到了一个错误:
数组值必须以“ {”或维度信息开头
ids_list character varying[] := ' || (SELECT COALESCE(quote_literal((array_agg(DISTINCT house_guid)) || ''',''' || quote_literal(array_agg(DISTINCT guid))), 'NULL') FROM tb) || ';
答案 0 :(得分:0)
使用array_agg
函数
with t1 as
(
select * from
(
select 'test_SQL_01' as ID
union
select 'test_SQL_02_PQR_01'
union
select 'test_SQL_03_055'
union
select 'test_SQL_04_ABC_99'
) as t
) select array_agg(ID) from t1
答案 1 :(得分:0)
您似乎在PL / pgSQL函数中使用了它。您应该改用SELECT ... INTO variable FROM...
:
declare
ids_list character varying[];
begin
.....
select array_agg(id)
into ids_list
from (
select house_guid
from tab
union
select guid
from tab
) t;
.... work with the ids_list variable
end;
UNION
将自动删除所有重复项(就像您尝试使用DISTINCT
一样。