SQL Error[42601]: Error: syntax error at or near "0"
SQL Error[42601]: Error: syntax error at or near "0"
我不明白如何从 select 中创建一个数组,我遇到了一个错误
SQL Error[42601]: Error: syntax error at or near "0"", Error occurred on dblink connection named "unnamed": could not execute query.
create temporary table house_address as
(SELECT full_address
FROM dblink('db_d',
'drop table if exists _x17092018;
create temporary table _x17092018 (
guid character varying,
full_address character varying,
address_guid character varying
);
do $$
declare
guids_list character varying[]
:= ''{(''' ||
(SELECT STRING_AGG(DISTINCT guid, ''', ''')
FROM lc) ||
''')}'';
r character varying;
begin
foreach r in array guids_list
loop
insert into _x17092018
select r, t.*
FROM sm.func_by_houseid(r, TRUE, ''db'') as t;
end loop;
END$$;'
) AS addr(full_address TEXT)
);
错误必须来自 guids_list
的初始化。
这样写,出来的时候会是这样的
{[guid1', 'guid ' containing spaces and quote', 'guid3]}
这显然不是您想要的。此外,正如我试图演示的那样,它对 SQL 注入是开放的。
你可以使用像
这样的东西
'guids_list character varying[] := ' ||
(SELECT quote_literal(array_agg(DISTINCT guid)) FROM lc) || ';'
我不明白如何从 select 中创建一个数组,我遇到了一个错误
SQL Error[42601]: Error: syntax error at or near "0"", Error occurred on dblink connection named "unnamed": could not execute query.
create temporary table house_address as
(SELECT full_address
FROM dblink('db_d',
'drop table if exists _x17092018;
create temporary table _x17092018 (
guid character varying,
full_address character varying,
address_guid character varying
);
do $$
declare
guids_list character varying[]
:= ''{(''' ||
(SELECT STRING_AGG(DISTINCT guid, ''', ''')
FROM lc) ||
''')}'';
r character varying;
begin
foreach r in array guids_list
loop
insert into _x17092018
select r, t.*
FROM sm.func_by_houseid(r, TRUE, ''db'') as t;
end loop;
END$$;'
) AS addr(full_address TEXT)
);
错误必须来自 guids_list
的初始化。
这样写,出来的时候会是这样的
{[guid1', 'guid ' containing spaces and quote', 'guid3]}
这显然不是您想要的。此外,正如我试图演示的那样,它对 SQL 注入是开放的。
你可以使用像
这样的东西'guids_list character varying[] := ' ||
(SELECT quote_literal(array_agg(DISTINCT guid)) FROM lc) || ';'