我想制作一个数组并加入两个id,但我犯了一个错误:
数组值必须以“{”或维度信息开头
ids_list character varying[] := ' || (SELECT COALESCE(quote_literal((array_agg(DISTINCT house_guid)) || ''',''' || quote_literal(array_agg(DISTINCT guid))), 'NULL') FROM tb) || ';
使用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
你似乎在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
一样)。