If nothing else, you could always add a select max(columnname) from tablename in the same transaction as the insert to get the value back. Not necessarily pretty. I'm sure that there's a better way, but I'm not familiar with PostgreSQL.
Update: I just did a quick google, and found http://lists.initd.org/pipermail/psycopg/2003-January/001656.html in which Colin Fox describes a better way:
The Postgres 'serial' type is really a shorthand for creating a sequence, and setting the default value of the field to the NEXTVAL() of the sequence.
You can use the CURVAL() function to determine the current value of a sequence, as long as you know the name of the sequence. Postgres follows a simple naming convention for the serial numbers: tablename_fieldname_seq, so in your case the sequence would be called test_id_seq:
--roboticusselect CURVAL('test_id_seq');
In reply to Re: Finding value of primary key (autoincrement) from last-inserted row with DBIx::Abstract and postgresql
by roboticus
in thread Finding value of primary key (autoincrement) from last-inserted row with DBIx::Abstract and postgresql
by ajkessel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |