Re: How use input parameter as path to COPY in function?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How use input parameter as path to COPY in function?
Дата
Msg-id 21110.1259208185@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How use input parameter as path to COPY in function?  (Bill Todd <pg@dbginc.com>)
Ответы Re: How use input parameter as path to COPY in function?  (Bill Todd <pg@dbginc.com>)
Список pgsql-general
Bill Todd <pg@dbginc.com> writes:
> I am missing something basic. How can I  use an input parameter as the
> destination path in a COPY statement in a function.

plpgsql can only substitute parameter values into places where a data
value is called for in a DML statement (ie, SELECT/INSERT/UPDATE/DELETE).
To use a parameter in other contexts, such as a utility statement like
COPY, you need to construct the command as a string and EXECUTE it.
Try something like

   EXECUTE 'copy dvd.genre to ' || quote_literal(export_path) ||
    $q$
     with
     delimiter as E'\t'
     null as ''
    $q$ ;

(There's any number of ways to do the quoting here, of course,
but I do strongly recommend using quote_literal() on the parameter.)

            regards, tom lane

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

Предыдущее
От: Bill Todd
Дата:
Сообщение: How use input parameter as path to COPY in function?
Следующее
От: Craig Ringer
Дата:
Сообщение: Wiki page on vacuum full