SQL错误[42601]:错误:语法错误为“0”或接近“0”

问题描述 投票:1回答:1

我无法理解如何从选择中创建一个数组,我有一个错误

SQL错误[42601]:错误:语法错误位于或接近“0”“,dblink连接上发生错误名为”unnamed“:无法执行查询。

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)
   );
sql postgresql plpgsql dblink
1个回答
1
投票

错误必须来自guids_list的初始化。

它的写作方式,它会像它一样出现

{[guid1', 'guid ' containing spaces and quote', 'guid3]}

这显然不是你想要的。此外,正如我试图演示的那样,SQL注入是开放的。

你可以用类似的东西

'guids_list character varying[] := ' ||
   (SELECT quote_literal(array_agg(DISTINCT guid)) FROM lc) || ';'
© www.soinside.com 2019 - 2024. All rights reserved.