Thread

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

    Vadim Mikheev <vmikheev@sectorbase.com> — 2001-08-31T16:45:49Z

    > 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().
    
    Vadim
    
    
  2. Re: [HACKERS] getting the oid for a new tuple in a BEFORE

    Bruce Momjian <pgman@candle.pha.pa.us> — 2001-09-04T15:33:30Z

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