Re: BUG #3662: Seems that more than one run of a functions causes an error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Robins Tharakan" <tharakan(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3662: Seems that more than one run of a functions causes an error
Date: 2007-10-11 00:00:18
Message-ID: 27859.1192060818@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Robins Tharakan" <tharakan(at)gmail(dot)com> writes:
> BEGIN
> CREATE TEMPORARY SEQUENCE s INCREMENT BY 1 START WITH 1;
> FOR rec in
> SELECT nextval('s') as rank, tt.scheme_code, tt.ret
> ...
> DROP SEQUENCE s;
> END;

Sorry, that's not going to work, for fundamentally the same reason that
references in this style to temp tables don't work --- the OID of the
sequence gets embedded into the nextval() call on first use of the
function. Consider creating the temp sequence just once per session
and resetting it on subsequent uses; or use EXECUTE to process that
SELECT. Or maybe you could dispense with the sequence altogether ---
a local-variable counter inside the function would be a vastly
lighter-weight solution anyway.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2007-10-11 00:12:17 Re: BUG #3662: Seems that more than one run of a functions causes an error
Previous Message Tom Lane 2007-10-10 21:32:17 Re: BUG #3668: type error in serial