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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Looking for help regarding getting the latest inserted sequence value.



--- Magnus Hagander <magnus(at)hagander(dot)net> wrote:

> If you're on 8.2 the easiest way is to use INSERT RETURNING. For example:
> INSERT INTO t (somefield) VALUES ('somevalue') RETURNING pkey
> 
> with pkey being the SERIAL field.

I don't want to derail the thread too much, but would it be nice if the returning could be used in
a insert sub-query?

INSERT INTO Childtable ( parentfkey, childname )
     VALUES ( ( INSERT INTO Parenttable ( parentname ) 
                     VALUES ( 'FRED' ) RETURNING pkey ), 'Jed');

This with one statement, you could insert into two or more tables.

Regards,
Richard Broersma Jr.



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group