From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
Cc: | Scott Ribe <scott_ribe(at)elevated-dev(dot)com>, Postgresql General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: scope quirk in copy in function |
Date: | 2015-03-23 14:38:32 |
Message-ID: | 32211.1427121512@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> writes:
> On 03/23/2015 06:59 AM, Scott Ribe wrote:
>> create or replace function archive_some_stuff() returns void as $$
>> declare cutoff timestamptz;
>> begin
>> cutoff := now() - '1 day'::interval;
>> copy (select * from log where end_when < cutoff) to ...
> "Variable substitution currently works only in SELECT, INSERT, UPDATE,
> and DELETE commands, because the main SQL engine allows query parameters
> only in these commands. To use a non-constant name or value in other
> statement types (generically called utility statements), you must
> construct the utility statement as a string and EXECUTE it."
Yeah. It seems like SELECT-inside-COPY might be worth special casing
though. ISTM this is more or less analogous to the case of PREPARE or
DECLARE CURSOR, which are also utility commands that contain a regular DML
command. I'm pretty sure there is a hack in there that allows parameters
to be transmitted down through PREPARE or D.C. ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2015-03-23 14:42:05 | Re: xml |
Previous Message | Adrian Klaver | 2015-03-23 14:19:30 | Re: scope quirk in copy in function |