From: Bruno Wolff III <bruno@wolff.to>
To: Michael Satterwhite <michael@weblore.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Question re: serial
Date: Sat, 24 Apr 2004 12:44:37 -0500
Message-ID: <20040424174437.GB19570@wolff.to> (raw)
In-Reply-To: <200404241224.05079.michael@weblore.com>
References: <200404241224.05079.michael@weblore.com>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, michael@weblore.com
Subject: Re: Question re: serial
In-Reply-To: <20040424174437.GB19570@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox