COPY FROM (query) in plpgsql

Поиск
Список
Период
Сортировка
От Marc Mamin
Тема COPY FROM (query) in plpgsql
Дата
Msg-id C4DAC901169B624F933534A26ED7DF310861B03E@JENMAIL01.ad.intershop.net
обсуждение исходный текст
Ответы Re: COPY FROM (query) in plpgsql  (Vincent Veyron <vv.lists@wanadoo.fr>)
Список pgsql-general
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:


EXECUTE 'insert into foo values (''a'',12,''ght'',45,1.2)';
EXECUTE 'insert into foo values (''b'',13,''ght'',45,1.1)';
EXECUTE 'insert into foo values (''a'',14,''ght'',45,1.5)';

(or

    EXECUTE 'insert into foo VALUES
     (''a'',12,''ght'',45,1.2),
     (''b'',13,''ght'',45,1.1),
     (''a'',14,''ght'',45,1.5)
     ';
)


I guess this could become faster with such a syntax:

COPY foo FROM
 (
   SELECT 'a,12,ght,45,1.2'
   UNION ALL
   SELECT 'b,13,ght,45,1.1'
   UNION ALL
   SELECT 'a,14,ght,45,1.5'
  ) WITH CSV;


best regards,

Marc Mamin

В списке pgsql-general по дате отправления:

Предыдущее
От: alexondi
Дата:
Сообщение: Wal archiving and streaming replication
Следующее
От: Ray Stell
Дата:
Сообщение: Re: Wal archiving and streaming replication