Re: COPY FROM (query) in plpgsql

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY FROM (query) in plpgsql
Date: 2011-09-10 11:08:01
Message-ID: j4fgeh$4pu$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2011-08-23, Marc Mamin <M(dot)Mamin(at)intershop(dot)de> wrote:
> 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:

you can wrap it up and cast it to foo:

insert into foo select(('('|| 'a,12,ght,45,1.2' ||')')::foo).*;
-- etc

insert into foo select ('(a,12,ght,45,1.2)'::foo).*
union all select ('(b,13,ght,45,1.1)'::foo).*
union all select ('(a,14,ght,45,1.5)'::foo).*;

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message mgould 2011-09-10 19:42:46 Security setup.
Previous Message Preston Landers 2011-09-10 00:14:24 Re: PG producing odd results on epoch timestamp to string conversion