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 17:25:11 |
Message-ID: | 93C04F1F5173D211A27900105AA8FCFC1453EF@lambic.prevuenet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Cool!!! I did not know this. Thanks for verifying how this works. I will
change my application to use currval instead of nextval.
-----Original Message-----
From: Ross J. Reedstrom [SMTP:reedstrm(at)rice(dot)edu]
Sent: Tuesday, April 20, 1999 10:33 AM
To: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] How to get seq after insert
Michael J Davis wrote:
>
> 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.
No, as Herouth pointed out, currval is multiuser-safe: it returns
the
last value given in the current session, and every user get's their
own
session. I just tried it out in two psql sessions to a test sequence
-
no matter how many calls to nextval I do in one window, the currval
in
each gives the write answer.
Ross
>
> -----Original Message-----
> From: Herouth Maoz [SMTP:herouth(at)oumail(dot)openu(dot)ac(dot)il]>
> 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.
>
--
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005
From | Date | Subject | |
---|---|---|---|
Next Message | JT Kirkpatrick | 1999-04-20 18:58:48 | TUPLES <> HEAP |
Previous Message | Ross J. Reedstrom | 1999-04-20 16:53:24 | Re: [GENERAL] How to get seq after insert |