Re: Allow COPY to use parameters - Mailing list pgsql-hackers

From Andrew Gierth
Subject Re: Allow COPY to use parameters
Date
Msg-id 87iny0htrr.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: Allow COPY to use parameters  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: Allow COPY to use parameters
List pgsql-hackers
>>>>> "Merlin" == Merlin Moncure <mmoncure@gmail.com> writes:

 Merlin> Note, the biggest pain point I have with COPY is not being able
 Merlin> to parameterize the filename argument.

Second proof of concept attached. This goes so far as to allow
statements like:

do $$
  declare t text := 'bar'; f text := '/tmp/copytest.dat';
  begin copy (select t, now()) to (f) csv header; end;
$$;

Also "copy foo to $1" or "copy (select * from foo where x=$1) to $2" and
so on should work from PQexecParams or in a plpgsql EXECUTE.

(I haven't tried to parameterize anything other than the filename and
query. Also, it does not accept arbitrary expressions - only $n, '...'
or a columnref. $n and '...' can have parens or not, but the columnref
must have them due to conflicts with unreserved keywords PROGRAM, STDIN,
STDOUT. This could be hacked around in other ways, I guess, if the
parens are too ugly.)

--
Andrew (irc:RhodiumToad)


Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: PATCH: pg_restore parallel-execution-deadlock issue
Next
From: Kyotaro HORIGUCHI
Date:
Subject: Re: Parallel pg_dump's error reporting doesn't work worth squat