In PostgreSQL, it is possible to put RETURNING
at the end of an INSERT
statement to return, say, the row's primary key value when that value is automatically set by a SERIAL
type.
How do I store this value in a variable that can be used to insert values into other tables?
Note that I want to insert the generated id
into multiple tables. A WITH
clause is, as far as I understand, only useful for a single insert. I take it that this will probably have to be done in PHP.
This is really the result of bad design; without a natural key, it is difficult to grab a unique row unless you have a handle on the primary key;