RE: [GENERAL] How to get seq after insert

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Michael Davis <michael(dot)davis(at)tvguide(dot)com>, "'Brian'" <signal(at)shreve(dot)net>, pgsql-general(at)postgreSQL(dot)org
Subject: RE: [GENERAL] How to get seq after insert
Date: 1999-04-20 11:04:04
Message-ID: l03130300b3420eefc12a@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 00:39 +0300 on 15/04/1999, Michael Davis wrote:

> The safest way is to select the nextval('seq_name') and then insert using
> this value.

No, actually, this is the unsafest way. This means that the logic is in the
frontend, not the backend. Besides, one can define the sequence as
read-only for the user who uses the database, but write for the one who
created the table that uses it, so that the user can't change the sequence
out of line.

To make a long story short, the best way is to let the insert statement use
the defaulet, and then use currval( 'seq_name' ). This gives you the last
value given in the current session. It is multiuser-safe, etc.

This was on the SQL list a couple of weeks ago. And by the way, the SQL
list is the proper list for this issue.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karl DeBisschop 1999-04-20 13:17:42 Re: [GENERAL] problem when vacuuming. . .
Previous Message Guo Ge 1999-04-20 06:36:07 request for Mr Stonebraker's E-mail address