Re: cvs text to quoted cvs text - Mailing list pgsql-sql

From Pavel Stehule
Subject Re: cvs text to quoted cvs text
Date
Msg-id CAFj8pRA5=2zt-dcZxdrm-eMM3=toCrGjwR1v-AO+fHUYPHthDQ@mail.gmail.com
Whole thread Raw
In response to cvs text to quoted cvs text  (Michael Moore <michaeljmoore@gmail.com>)
Responses Re: cvs text to quoted cvs text
List pgsql-sql
Hi

2016-09-26 21:23 GMT+02:00 Michael Moore <michaeljmoore@gmail.com>:
I have some input parameters on a function that will by use in dynamic sql as part of an IN list. For example:
'select val from mytab where zzz in ('||csv_input_parm::text||')';
The problem is that csv_input_parm is formatted like:
[THIS,THAT,THE OTHER] while the IN list would need
['THIS','THAT','THE OTHER'] brackets not included.
I came up with this approach to do the conversion:
select ''''||array_to_string(string_to_array('THIS,THAT,THE OTHER',','),''',''')||'''' rslt
It gets the job done, but it's ugly. Is there a way that is not ugly?

are you need it? You can use USING clause, when you use dynamic SQL.

postgres=# DO $$
DECLARE x text[] = '{AHOJ,NAZDAR}'; r text;
BEGIN
  FOR r IN EXECUTE 'SELECT UNNEST($1)' USING x
  LOOP
    RAISE NOTICE '>>>%<<<', r;
  END LOOP;
END;
$$;
NOTICE:  >>>AHOJ<<<
NOTICE:  >>>NAZDAR<<<
DO

Regards

Pavel
 
thanks,
Mike
 

pgsql-sql by date:

Previous
From: Igor Neyman
Date:
Subject: Re: cvs text to quoted cvs text
Next
From: Michael Moore
Date:
Subject: Re: cvs text to quoted cvs text