From: | Michael J Davis <michael(dot)j(dot)davis(at)tvguide(dot)com> |
---|---|
To: | pgsql-general(at)postgreSQL(dot)org |
Subject: | RE: [GENERAL] How to get seq after insert |
Date: | 1999-04-20 16:08:43 |
Message-ID: | 93C04F1F5173D211A27900105AA8FCFC1453ED@lambic.prevuenet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
If two users insert into the same table at the same time, one of the users
will get the wrong currval back. I still believe that getting the nextval
first is the safest way. It may create holes when an insert fails, but this
is better than getting back the wrong curval.
-----Original Message-----
From: Herouth Maoz [SMTP:herouth(at)oumail(dot)openu(dot)ac(dot)il]
Sent: Tuesday, April 20, 1999 5:04 AM
To: Michael Davis; 'Brian'; pgsql-general(at)postgreSQL(dot)org
Subject: RE: [GENERAL] How to get seq after insert
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
From | Date | Subject | |
---|---|---|---|
Next Message | amarof | 1999-04-20 16:20:22 | help |
Previous Message | Thomas Lockhart | 1999-04-20 14:40:05 | Re: [INTERFACES] where did that date and time come from?? |