Received: from candle.pha.pa.us (candle.navpoint.com [162.33.245.46]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f84FXg797037; Tue, 4 Sep 2001 11:33:42 -0400 (EDT) (envelope-from pgman@candle.pha.pa.us) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id f84FXUc09905; Tue, 4 Sep 2001 11:33:30 -0400 (EDT) From: Bruce Momjian Message-Id: <200109041533.f84FXUc09905@candle.pha.pa.us> Subject: Re: [HACKERS] getting the oid for a new tuple in a BEFORE In-Reply-To: <3705826352029646A3E91C53F7189E32016761@sectorbase2.sectorbase.com> "from Mikheev, Vadim at Aug 31, 2001 09:45:49 am" To: "Mikheev, Vadim" Date: Tue, 4 Sep 2001 11:33:30 -0400 (EDT) CC: "'Markus Wagner'" , pgsql-general@postgresql.org, pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org X-Mailer: ELM [version 2.4ME+ PL90 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200109/97 X-Sequence-Number: 14711 > > we need to control database changes within BEFORE triggers. > > There is no problem with triggers called by update, but there is > > a problem with triggers called by insert. > > > > We strongly need to know the oid of a newly inserted tuple. > > In this case, we use tg_newtuple of the TriggerData structure > > passed to thetrigger function, and its t_data -> t_oid will > > have the value '0'. > > > > Using BEFORE and AFTER triggers would make our lives much harder. > > > > Is there any way (even hack) to get the oid the newly > > inserted tuple will receive? > > Just set t_data->t_oid = newoid() - this is what backend does > in heapam.c:heap_insert(). Does that work? Doesn't that get overwritten when the actual INSERT happens? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026