Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 1E50E2E39A5 for ; Tue, 22 Jan 2008 05:14:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 35709-09 for ; Tue, 22 Jan 2008 05:14:00 -0400 (AST) Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id CFE092E180D for ; Tue, 22 Jan 2008 05:14:00 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay05.plus.net with esmtp (Exim) id 1JHFCg-0005S8-63; Tue, 22 Jan 2008 09:13:58 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 02EFF274072; Tue, 22 Jan 2008 09:13:57 +0000 (GMT) Message-ID: <4795B3D4.5020201@archonet.com> Date: Tue, 22 Jan 2008 09:13:56 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: sad CC: pgsql-sql@postgresql.org Subject: Re: currval() within one statement References: <4795984E.7030904@bankir.ru> <20080122073637.GB21676@a-kretschmer.de> <4795A152.3080400@bankir.ru> In-Reply-To: <4795A152.3080400@bankir.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/167 X-Sequence-Number: 30020 sad wrote: > A. Kretschmer wrote: > >>> is it expected that the currval() changes its value between calls >>> within one statement ? > >> Conclusion, don't call nextval() within a TRIGGER, and insert either >> nextval() for the column or omit this column. > > I only note that i still want to discuss the titled problem or to be > given an exact pointer to documentation regarding the currval() behavior > in the described situation, that i had. Well, the page in the docs isn't hard to find - http://www.postgresql.org/docs/8.2/static/functions-sequence.html But surely it works exactly as you would expect it to. nextval(S) advances the sequence and returns the new value currval(S) returns the current value of sequence S, which is whatever the previous call to nextval(S) returned. In the even you haven't called nextval(S) then it is undefined. What do you think should happen? -- Richard Huxton Archonet Ltd