Thread: getting the oid for a new tuple in a BEFORE trigger

getting the oid for a new tuple in a BEFORE trigger

From
Markus Wagner
Date:
Hi,

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?

Thank you very much,

Markus


Re: getting the oid for a new tuple in a BEFORE trigger

From
"omid omoomi"
Date:
hi,
Idon't know the best way but how about a quick insert in a temp table and
adding 1 to the inserted oid column each time the trigger will run.!
regards
Omid
>From: Markus Wagner <wagner@imsd.uni-mainz.de>
>To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org,
>pgsql-hackers@postgresql.org
>Subject: [SQL] getting the oid for a new tuple in a BEFORE trigger
>Date: Wed, 29 Aug 2001 11:15:08 +0200
>
>Hi,
>
>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?
>
>Thank you very much,
>
>Markus
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
>subscribe-nomail command to majordomo@postgresql.org so that your
>message can get through to the mailing list cleanly


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


Re: getting the oid for a new tuple in a BEFORE trigger

From
"Josh Berkus"
Date:
Mark,

The responses to your problem are gonna be kinda slow, as 2/3 of the
core team, and many of the users, are at the Expo right now (and if
anyone on the list is in the SF Bay Area, join us!  BOF session
tonight!)

> 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.

What problem?

> 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.

Once again, why?

> Is there any way (even hack) to get the oid the newly inserted tuple
> will
> receive?

This specific answer will have to come from someone else.

I could suggest a couple of workarounds, if you gave a fuller
description of exactly what you're trying to accomplish.

-Josh Berkus

P.S. Please do not cross-post to more than 2 lists at a time.  The
Postgres lists have been kept to a managable volume to date; let's keep
it that way.


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Attachment

Re: getting the oid for a new tuple in a BEFORE trigger

From
Francesco Casadei
Date:
On Wed, Aug 29, 2001 at 11:15:08AM +0200, Markus Wagner wrote:
> Hi,
>
> 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?
>
> Thank you very much,
>
> Markus
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
> end of the original message

Read section 24.2.5.4 'Obtaining other results status' of the Programmer's
Guide. This is for the PL/pgSQL language, though.

    Francesco Casadei

Re: getting the oid for a new tuple in a BEFORE trigger

From
Peter Eisentraut
Date:
Markus Wagner writes:

> 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'.

A less hackish way to do this might be using a sequence object for the
primary key and fetch the next sequence value manually.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter