Re: COPY FROM (query) in plpgsql

From: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY FROM (query) in plpgsql
Date: 2011-08-23 14:59:23
Message-ID: 1314111563.2295.55.camel@asus-1001PX.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Le mardi 23 août 2011 à 11:29 +0200, Marc Mamin a écrit :
> Hello,
>
> there seems to be no way to use COPY this way, so I guess this is a
> feature request...
>
> this may also help users who tried using COPY FROM STDIN in plpgsql.
>
>
> I have a query with a lot of string manipulation that returns data as
> single strings, e.g.:
>
>
> 'a,12,ght,45,1.2'
> 'b,13,ght,45,1.1'
> 'a,14,ght,45,1.5'
>
>
> in order to save this result into a table, I still need to quote the
> string value and use EXECUTE:
>

If you can write the data to disk, this gets you rid of the quote
problem :

COPY query TO 'file.csv';

COPY foo FROM 'file.csv' WITH CSV DELIMITER ',';

--
Vincent Veyron
http://marica.fr/
Logiciel de gestion des sinistres et des contentieux pour le service juridique

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raghavendra 2011-08-23 15:00:55 Re: Wal archiving and streaming replication
Previous Message Guillaume Lelarge 2011-08-23 14:45:50 Re: GRANT privileges strange behavior