Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 8BFEA2E384D for ; Tue, 22 Jan 2008 06:22:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 78933-03-7 for ; Tue, 22 Jan 2008 06:21:55 -0400 (AST) Received: from office.antora.ru (unknown [195.151.214.69]) by postgresql.org (Postfix) with ESMTP id A9C422E33D0 for ; Tue, 22 Jan 2008 06:21:55 -0400 (AST) Received: from [192.168.1.124] by office.antora.ru with esmtpa (Exim 4.63) (envelope-from ) id 1JHGGK-0000RI-8Q; Tue, 22 Jan 2008 13:21:48 +0300 Message-ID: <4795C3E8.9080607@bankir.ru> Date: Tue, 22 Jan 2008 13:22:32 +0300 From: sad User-Agent: Thunderbird 2.0.0.4 (X11/20070626) MIME-Version: 1.0 To: Richard Huxton 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> <4795B3D4.5020201@archonet.com> In-Reply-To: <4795B3D4.5020201@archonet.com> 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/168 X-Sequence-Number: 30021 Richard Huxton wrote: > 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. Then this is the question on the execution order of the statement INSERT...SELECT... > What do you think should happen? I had expected all the currval() calls to be called before all the triggers fired.