X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 98D26D1B4E4 for ; Sat, 15 Nov 2003 15:40:56 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 38832-05 for ; Sat, 15 Nov 2003 11:40:29 -0400 (AST) Received: from mwinf0602.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.25]) by svr1.postgresql.org (Postfix) with ESMTP id B53CAD1B4EB for ; Sat, 15 Nov 2003 11:40:24 -0400 (AST) Received: from gina (ASte-Genev-Bois-102-1-4-233.w80-11.abo.wanadoo.fr [80.11.203.233]) by mwinf0602.wanadoo.fr (SMTP Server) with ESMTP id 5432C540027C; Sat, 15 Nov 2003 16:40:28 +0100 (CET) From: Guillaume LELARGE Organization: traduc.org To: Yasir Malik Subject: Re: Getting last insert value Date: Sat, 15 Nov 2003 16:40:42 +0000 User-Agent: KMail/1.5.3 References: In-Reply-To: Cc: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200311151640.42892.gleu@wanadoo.fr> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/167 X-Sequence-Number: 15982 Le Samedi 15 Novembre 2003 15:18, vous avez =E9crit : > 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=20 http://www.postgresql.org/docs/7.3/interactive/functions-sequence.html --=20 Guillaume .