Re: Question re: serial - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: Question re: serial
Date
Msg-id 20040424174437.GB19570@wolff.to
Whole thread Raw
In response to Question re: serial  (Michael Satterwhite <michael@weblore.com>)
List pgsql-sql
On Sat, Apr 24, 2004 at 12:24:03 -0500, Michael Satterwhite <michael@weblore.com> 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.


pgsql-sql by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: Question re: serial
Next
From: Michael Satterwhite
Date:
Subject: Python connection