Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 1E9132E2F12 for ; Tue, 22 Jan 2008 08:18:54 -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 00321-06 for ; Tue, 22 Jan 2008 08:18:51 -0400 (AST) Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id 515B92E2DDD for ; Tue, 22 Jan 2008 08:18:51 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay05.plus.net with esmtp (Exim) id 1JHI5X-0000RS-Te; Tue, 22 Jan 2008 12:18:48 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id ED382274093; Tue, 22 Jan 2008 12:18:46 +0000 (GMT) Message-ID: <4795DF27.5030602@archonet.com> Date: Tue, 22 Jan 2008 12:18:47 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: silly_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> <4795B3D4.5020201@archonet.com> <4795C3E8.9080607@bankir.ru> <4795C7E8.6030903@archonet.com> <4795D321.5050409@bankir.ru> In-Reply-To: <4795D321.5050409@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/173 X-Sequence-Number: 30026 silly_sad wrote: > > id default value is always set by the trigger before insert on each > table for each row. > > The particular subproblem is to > insert one record into ttt1 > and then insert corresponding record into ttt, > ___This is the place to use currval. I'd be tempted to turn it the other way around and have an AFTER trigger that just uses NEW.id as the value to put into "ttt". The reason to use an AFTER trigger is that you know the value can't be changed at that point, whereas with a BEFORE trigger it might. In your case it doesn't matter, but it's probably a good idea to be consistent in these things. -- Richard Huxton Archonet Ltd