scope quirk in copy in function

From: Scott Ribe <scott_ribe(at)elevated-dev(dot)com>
To: Postgresql General <pgsql-general(at)postgresql(dot)org>
Subject: scope quirk in copy in function
Date: 2015-03-23 13:59:17
Message-ID: 84BAAF8D-20EF-451A-A055-17BBC78CD864@elevated-dev.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 ...
...

Gives me an error that there is column named cutoff. (Other uses of cutoff in queries not inside a copy, iow the delete from commands, work.)

Is there any alternative to just duplicating the now() expression inside every copy?

--
Scott Ribe
scott_ribe(at)elevated-dev(dot)com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2015-03-23 14:09:43 Re: xml
Previous Message Pavel Stehule 2015-03-23 12:30:44 Re: xml