I want to compare my comma delimited string with column values.
I did the following, which is not returning the expected result. ll = '"Java,CPP"' is coming dynamically.
create or replace function testing(ll text)
returns void as
$body$
Declare
       foo text[];
       ko text[];
BEGIN
       select unique_code into foo from codings
       where  unique_code = ANY (regexp_split_to_array(ll, '\,'));
       raise info '%',foo;
END;
$body$
Language plpgsql;
I got below error
ERROR: column "Java,CPP" does not exist LINE 1: SELECT "Java,CPP" ^ QUERY: SELECT "Java,CPP" CONTEXT: PL/pgSQL function testing() line 8 at assignment
The value of ll is coming dynamically like above and now it is return NULL also in the row I have 'Java' and 'Cpp', both values in matching case.
select unique_code from codings;
unique_code
  Java
  Python
  CPP
  C
  Haskell
I also tried trim but not work. The updated code is here:
create or replace function testing(ll text)
returns void as
$body$
Declare
       foo text[];
       --ll text;
       ko text[];
       oo text;
BEGIN
      --oo := replace(ll,'"','');
      raise info '%',regexp_split_to_array(trim(both '"' from ll), '\,');
      ko := regexp_split_to_array(trim(both '"' from ll), '\,');
       ---ll := "CH-PREP,CH-PRMB";
       --select(regexp_split_to_array(ll, '\|')) into ko;
        --foo := array(select unique_key from membership_map);
       select  unique_code into foo from codings where  unique_code = ANY(ko);
       raise info '%',foo;
       --raise info '%', ko;
END;
$body$
Language plpgsql;
Then:
select testing('"Java,CPP"');
ERROR: malformed array literal: "Java" DETAIL: Array value must start with "{" or dimension information CONTEXT: PL/pgSQL function testing(text) line 16 at SQL statement
 
     
    