COPY support for parameters

Поиск
Список
Период
Сортировка
От Adrian Phinney
Тема COPY support for parameters
Дата
Msg-id CAB6u-ei4sCoUQnkXA1fL=1g=6cX7djWh_xSTHqz0fnngkuJ5mQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: COPY support for parameters  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello,

I'm trying to add support for specifying parameters when using a COPY command to Npgsql (.NET's Postgres provider): https://github.com/npgsql/npgsql/pull/2332

I've used the extended query protocol to send the COPY command. When I send a COPY command without parameters, the backend issues the appropriate CopyOutResponse/CopyInResponse/CopyData:

> COPY (select generate_series(1, 5)) TO STDOUT

When I add parameters, the backend will issue an ErrorResponse message after issuing the ParseComplete and BindComplete messages:

> COPY (select generate_series(1, $1)) TO STDOUT
> Error: 42P02: there is no parameter $1

The owner of Npgsql confirmed that my use of the protocol seems correct (parameters going over the wire, etc) but Postgres doesn't seem to be resolving the parameters. Does Postgres support COPY with parameters?

More background on my use case: I'd like to be able to use COPY to efficiently generate a CSV from our database with parameters are specified. For example, generating a CSV of users recently created:

COPY (SELECT id, name, email FROM USERS where date_created > $1) TO STDOUT WITH (DELIMITER ',', FORMAT CSV, HEADER true, ENCODING 'UTF8')

If COPY doesn't support parameters, we're required to build the SELECT using quote_literal() or format() with the L format specifier -- both of which are less safe than using a parameterized query when the parameter comes from a user.

Thanks,

Adrian Phinney

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Early WIP/PoC for inlining CTEs
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: Ryu floating point output patch