Search Postgresql Archives

Re: Example of RETURNING clause to get auto-generated keys

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

 



Adam Rich wrote:
Let's say you have a table with "id, value" columns.

And your normal query would be this:

INSERT into mytable (id,value) values (1,"foo"),(2,"bar");

Your new query would be like this:

INSERT into mytable (id,value) values (1,"foo"),(2,"bar")
RETURNING id;

And you would get a result back with one column (id) and
two rows (the newly inserted keys).  You can also return
other fields if you like, you're not limited to just the
generated keys.



Thank you Alvaro and Adam,

Now playing devil's advocate, can anyone see scenarios where this will not work as expected? Examples (descriptions not sql necessarily) of those would be helpful too...

Ken




[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