Re: [GENERAL] Insert and obtain the pk

2003-11-06 Thread Alvaro Herrera
On Thu, Nov 06, 2003 at 12:26:48PM -0600, Eliu Montoya wrote: > Does anyone know an easy way to insert a record (without a value for the > primary key because it is a sequence) and at the same time obtain the value > of primary key that was assign to this new record. Given that you are already

Re: [GENERAL] Insert and obtain the pk

2003-11-06 Thread Ian Harding
Actually, it's tablename_columname_seq , unless that exceeds namedatalen. It shouldn't. Mine never do... But if it does, there is an algorithm for truncating the table and/or field name to fit. >>> Adam Ruth <[EMAIL PROTECTED]> 11/06/03 11:46AM >>> You can call currval on the sequence that pro

Re: [GENERAL] Insert and obtain the pk

2003-11-06 Thread Adam Ruth
You can call currval on the sequence that provided the value for the primary key. It's guaranteed to be the last value retrieved from that sequence *for your session*. insert into table1 (f1, f2) values ('a', 'b'); select currval('table1_seq'); Use the name of your sequence. If the primary key