我试图在其他地方取消一个数组来查询postgres数据库

时间:2014-11-06 17:16:59

标签: postgresql

我正在调用该函数,但它返回的错误是数组值必须以" {"或维度信息使用

    Create or Replace Function get_post_process_info(IN v_esdt_pp character varying[])
Returns setof Record as 
$$
Declare 
post_processes RECORD;
esdt_value character varying;
v_sdsname character varying[];
v_dimension character varying[];
counter int := 1;
Begin
    -- to loop through the array and get the values for the esdt_values
    FOR esdt_value IN select * from unnest(v_esdt_pp)
    LOOP

    -- esdt_values as a key for the multi-dimensional arrays and also as the where clause value
    SELECT distinct on ("SdsName") "SdsName" into  v_sdsname from "Collection_ESDT_SDS_Def" where "ESDT" = esdt_values;
    raise notice'esdt_value: %',esdt_value;

    END LOOP;

  Return ;
End
$$ Language plpgsql;



Select get_post_process_info(array['ab','bc]);

1 个答案:

答案 0 :(得分:0)

您的功能已消毒:

CREATE OR REPLACE FUNCTION get_post_process_info(v_esdt_pp text[])
  RETURNS SETOF record AS
$func$
DECLARE
   esdt_value text;
   v_sdsname text[];
   v_dimension text[];
   counter int := 1;
BEGIN
   FOR esdt_value IN
      SELECT * FROM unnest(v_esdt_pp) t
   LOOP
      SELECT distinct "SdsName" INTO v_sdsname
      FROM  "Collection_ESDT_SDS_Def"
      WHERE "ESDT" = esdt_value;

      RAISE NOTICE 'esdt_value: %', esdt_value;
   END LOOP;
END
$func$ Language plpgsql;

呼叫:

Select get_post_process_info('{ab,bc}'::text[]);

DISTINCT代替DISTINCT ON,缺少表格别名,格式化,有些残缺,...... 最后是错误的直接原因:通话中缺少引号。

整个shebang可以用一个SQL语句替换 但是,显然,你的功能是不完整的。什么都没归还。缺少信息。