From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net> |
Cc: | postgresql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: last inserted raw (identity) |
Date: | 2003-08-02 04:09:16 |
Message-ID: | 20030802040916.GD27983@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Aug 01, 2003 at 10:43:03PM -0500, Ron Johnson wrote:
> On Fri, 2003-08-01 at 22:27, Martijn van Oosterhout wrote:
> > On Fri, Aug 01, 2003 at 04:25:05PM -0700, b b wrote:
> > >
> > > Is there an environment variable that returns the
> > > primary key of the last inserted row. This is usefull
> > > if you insert a rwo and need the primary key to insert
> > > it into another table as a foreign key.
> > >
> > > In MS-SQL that is equivalent to @@identity variable:
> > > insert into organization ('org name', ....)
> > > insert into contact (@@identity, 'contact name'
> > > .....)
> > > Here Identity is the organization's ID that is needed
> > > as a foreign key in contact table.
> >
> > See currval() and nextval().
>
> What if his PK isn't a sequence?
Hadn't thought of that. It would have been part of the insert then, in which
case it may be possible for the application to grab it internally.
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> "All that is needed for the forces of evil to triumph is for enough good
> men to do nothing." - Edmond Burke
> "The penalty good people pay for not being interested in politics is to be
> governed by people worse than themselves." - Plato
From | Date | Subject | |
---|---|---|---|
Next Message | nolan | 2003-08-02 04:18:30 | Re: last inserted raw (identity) |
Previous Message | Tom Lane | 2003-08-02 04:06:19 | Re: Using contrib/fulltext on multiple tables. |