Skip site navigation (1) Skip section navigation (2)

Re: trigger that needs a PK

From: johnf <jfabiani(at)yolo(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: trigger that needs a PK
Date: 2008-02-13 16:14:10
Message-ID: 200802130814.10681.jfabiani@yolo.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Wednesday 13 February 2008 07:25:02 am Tom Lane wrote:
> "A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> writes:
> > am  Tue, dem 12.02.2008, um 23:20:46 -0800 mailte johnf folgendes:
> >> The problem is I can not determine what the parent pk is for the insert
> >> into the child because it hasn't happen yet - if I set the trigger to
> >> before insert.  So I guess I need something that works with after insert
> >> into the parent so the pkid can be created.
> >
> > You don't need a TRIGGER, you need currval().
>
> I think this advice is entirely misleading.  As best I can tell, the
> OP's problem is best solved with an ON INSERT trigger on the parent
> table, and all he's got to do is look at the NEW field for the PK.
> He is mistaken to think that the value won't have been assigned yet
> when the trigger is fired (and if he was right, then currval would
> be no solution either).  AFAICS using currval is just useless
> complication.
>
> 			regards, tom lane

Thanks Tom,

I was able to discover the new had my PK after all.  I decided to use the 
trigger and all appears to be working for the moment.


-- 
John Fabiani

In response to

pgsql-novice by date

Next:From: Sachin SrivastavaDate: 2008-02-14 06:38:13
Subject: How to test changes done to the code
Previous:From: Tom LaneDate: 2008-02-13 15:25:02
Subject: Re: trigger that needs a PK

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group