Re: Question re: serial

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Michael Satterwhite <michael(at)weblore(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Question re: serial
Date: 2004-04-24 17:44:37
Message-ID: 20040424174437.GB19570@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Apr 24, 2004 at 12:24:03 -0500,
Michael Satterwhite <michael(at)weblore(dot)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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Satterwhite 2004-04-25 16:29:54 Python connection
Previous Message Devrim GUNDUZ 2004-04-24 17:37:44 Re: Question re: serial