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 F3540D1B4A0 for ; Sat, 24 Apr 2004 14:40:31 -0300 (ADT) 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 74094-02 for ; Sat, 24 Apr 2004 14:40:31 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id DE28BD1B496 for ; Sat, 24 Apr 2004 14:40:29 -0300 (ADT) Received: (qmail 19956 invoked by uid 500); 24 Apr 2004 17:44:37 -0000 Date: Sat, 24 Apr 2004 12:44:37 -0500 From: Bruno Wolff III To: Michael Satterwhite Cc: pgsql-sql@postgresql.org Subject: Re: Question re: serial Message-ID: <20040424174437.GB19570@wolff.to> Mail-Followup-To: Michael Satterwhite , pgsql-sql@postgresql.org References: <200404241224.05079.michael@weblore.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200404241224.05079.michael@weblore.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200404/269 X-Sequence-Number: 17644 On Sat, Apr 24, 2004 at 12:24:03 -0500, Michael Satterwhite wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I have a table with a primary key defined as serial unique. When I insert a > row into the table, I need to get the value of that row back so that I can > use it to link rows in another table to it. How do I do that in Postgresql? I > know that I can define a sequence and insert the value manually, but is there > a way to query the value of the most recently inserted serial column of a > row? When you use a serial type there a sequence is created for you. You can reference the most recent value of that sequence within the current session using currval. You can use the \d command in psql to see what sequence is being used to calculate the default value.