Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] getting the currval of a sequence

From: James Olin Oden <joden(at)lee(dot)k12(dot)nc(dot)us>
To: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] getting the currval of a sequence
Date: 1998-08-14 15:30:16
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general

> > > I think you should just go with what Vadim suggested and use:
> > >         select currval('my_sequence');
> > > This will be the same within a transaction, even if there is another
> > > transaction using the same sequence.
> >
> > Sorry, I wasn't thinking of it happening in the same transaction.  In
> > that
> > case that would be the thing to do.  If on the other hand you needed
> > that
> > number over multiple transactions, wouldn't what I had suggested work?
> >
> > ...james
> >
> Yes it would, but your suggestion introduces problems of it's own.  The
> whole point of a transaction is encapsulate a logical unit of work, such
> that it all succeeds together or it all fails together.  This would
> include the incrementing of the sequence.  The way that you are
> suggestion you would always increment the sequence even if you never
> used it, it just seems like a waste to me

Yikes, I didn't think of that.  I suppose with 4 billion sequence numbers
you could waste a few, but...things always seem grow beyon their intended
purposes.  I guess your absolutely right on this one...james

In response to

pgsql-general by date

Next:From: Kapoor, Nishikant XDate: 1998-08-14 17:03:48
Subject: No DB connection in Netscape ? Please help.
Previous:From: Jackson, DeJuanDate: 1998-08-14 15:05:15
Subject: RE: [GENERAL] getting the currval of a sequence

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group