From: | Guillaume LELARGE <gleu(at)wanadoo(dot)fr> |
---|---|
To: | Yasir Malik <ymalik(at)cs(dot)stevens-tech(dot)edu> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Getting last insert value |
Date: | 2003-11-15 16:40:42 |
Message-ID: | 200311151640.42892.gleu@wanadoo.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Le Samedi 15 Novembre 2003 15:18, vous avez écrit :
> Hello,
> I have a table with many fields, and one of the fields is of type serial.
> I will do many inserts, and there will be many repeats of the other fields
> in the table, but, obviously, the serial field will be unique for all the
> rows. How can I get the value of serial field of the last row I inserted.
> I know I can select the maximum value from the serial field, but is there
> a better way, preferably something that takes constant time.
> Thanks,
> Yasir Malik
>
Doing a "select currval() from my_table" after your insert should work.
For more details, see
http://www.postgresql.org/docs/7.3/interactive/functions-sequence.html
--
Guillaume
<!-- http://absfr.tuxfamily.org/
http://pgsql-fr.tuxfamily.org/ -->.
From | Date | Subject | |
---|---|---|---|
Next Message | Guillaume LELARGE | 2003-11-15 17:41:41 | Re: Getting last insert value |
Previous Message | Peter Eisentraut | 2003-11-15 16:36:39 | Re: Programatically switching database |