Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- Magnus Hagander <magnus@xxxxxxxxxxxx> 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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux