Re: [GENERAL] performance issue using DBI
Re: [GENERAL] performance issue using DBI
On Thu, 2002-06-06 at 14:55, Joshua b. Jore wrote:u
> Don't use currval since some other process might alter the
> sequence between the time you call nextval and currval.
This is wrong. currval() will always return the last serial assigned in
*the*same*session*. It is not affected by other users at all.
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
"Therefore being justified by faith, we have peace with
God through our Lord Jesus Christ." Romans 5:1
Re: [GENERAL] performance issue using DBI
От:
"Dan Langille" <dan@langille.org>
Дата:
On 6 Jun 2002 at 17:14, Oliver Elphick wrote:
> On Thu, 2002-06-06 at 14:55, Joshua b. Jore wrote:u
> > Don't use currval since some other process might alter the
> > sequence between the time you call nextval and currval.
>
> This is wrong. currval() will always return the last serial assigned in
> *the*same*session*. It is not affected by other users at all.
Folks, here's a short test which might help. Note the BEGIN.
$ psql testing
testing=# create sequence test;
CREATE
testing=# select currval('test');
ERROR: test.currval is not yet defined in this session
testing=# select setval('test', 1);
setval
--------
1
(1 row)
testing=# select currval('test');
currval
---------
1
(1 row)
testing=# select currval('test');
currval
---------
1
(1 row)
testing=# select currval('test');
currval
---------
1
(1 row)
testing=# select currval('test');
currval
---------
1
(1 row)
testing=#
Then, in another window, I did this:
$ psql testing
# select nextval('test');
nextval
---------
2
(1 row)
testing=# select nextval('test');
nextval
---------
3
(1 row)
testing=# select nextval('test');
nextval
---------
4
(1 row)
testing=#
Then back to the other window:
testing=# select currval('test');
currval
---------
1
(1 row)
testing=# select nextval('test');
nextval
---------
5
(1 row)
testing=#
cheers
FWIW: I always use nextval when looking for a new ID.
--
Dan Langille
Re: [GENERAL] performance issue using DBI
От:
"Joshua b. Jore" <josh@greentechnologist.org>
Дата:
Oh ok. So I was thinking of the way that sequences cut across transactions and I misinterpreted it. Thanks for the clarification. Joshua b. Jore ; http://www.greentechnologist.org ; 1121 1233 1311 200 1201 1302 1211 200 1201 1303 200 1300 1233 1313 1211 1302 1212 1311 1230 200 1201 1303 200 1321 1233 1311 1302 200 1211 1232 1211 1231 1321 200 1310 1220 1221 1232 1223 1303 200 1321 1233 1311 200 1201 1302 1211 232 200 1112 1233 1310 1211 200 1013 1302 1211 1211 1232 201 22 On 6 Jun 2002, Oliver Elphick wrote: > On Thu, 2002-06-06 at 14:55, Joshua b. Jore wrote:u > > Don't use currval since some other process might alter the > > sequence between the time you call nextval and currval. > > This is wrong. currval() will always return the last serial assigned in > *the*same*session*. It is not affected by other users at all. > > -- > Oliver Elphick Oliver.Elphick@lfix.co.uk > Isle of Wight http://www.lfix.co.uk/oliver > GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C > > "Therefore being justified by faith, we have peace with > God through our Lord Jesus Christ." Romans 5:1 >