Re: Seral field value after INSERT !

From: "Gregory Wood" <gregw(at)com-stock(dot)com>
To: Berényi Gábor <Berenyi(dot)Gabor(at)posta(dot)hu>
Cc: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Seral field value after INSERT !
Date: 2001-04-26 14:29:09
Message-ID: 00f601c0ce5d$e29af3a0$7889ffcc@comstock.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I have been inserting records into a table using the SQL insert statement.
> One of the field types is serial, and I have been
> trying to figure out how to get the value that was assigned in the field
as
> a result of the insert. The serial typed field is the only one guaranteed
> to be unique, so I can't really do a search, and there are several people
> adding data at once, so I can't reliable guess. Can anyone help?

You can get the serial value by doing a SELECT currval('SeqName'); after
performing the insert. That value will be correct for the last INSERT
performed *by that backend*. This means that if each of those people are
adding data at once, one particular person will see only the last value that
that person inserted regardless of what the actual last value inserted was.

The SeqName for a serial is usually just <TableName>_<SerialField>_SEQ.
There is a character limit, so if you have really long field table/field
names, you might have to look at the system catalogs.

Greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message psycle 2001-04-26 14:32:43 Scalability Supported ?
Previous Message will trillich 2001-04-26 14:27:43 Re: Seral field value after INSERT !