Re: using sequences - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: using sequences
Date
Msg-id 20030614122124.GA27374@wolff.to
Whole thread Raw
In response to Re: using sequences  (Erik Price <eprice@ptc.com>)
Responses Re: using sequences  (Erik Price <eprice@ptc.com>)
List pgsql-general
On Fri, Jun 13, 2003 at 17:29:01 -0400,
  Erik Price <eprice@ptc.com> wrote:
>
>
> Bruno Wolff III wrote:
>
> >If you are trying to do this you probably don't really understand
> >sequences.
> >There aren't any common good reasons for trying to get the value of a
> >sequence
> >before you have generated a value in the current session.
>
> It seems you're right that I dont understand them.  However, I don't
> have any intent of calling it like this (without having generated a
> value), rather, I was simply curious and playing around with the
> commandline client, and following some instructions I had seen in
> another post.  I didn't realize that it needed to be "activated" for the
> current session.

"activated" isn't really the right word. When you call nextval you are
giving a number that is unique. No one else gets to see that number
(until you save it somewhere) which prevents contention between different
connections trying to get unique numbers from the same sequence.
currval is just a way to see the last value of nextval that was given to
you. If one hasn't been given to you, then there isn't anything for
currval to return.

Related to this is that you should only use the uniqueness of sequence
values. You shouldn't expect them to be continuous and you shouldn't
expect them to be monotonicly increasing other than within a single
session.

pgsql-general by date:

Previous
From: Jason Godden
Date:
Subject: Growing Database Size Solved
Next
From: Bruno Wolff III
Date:
Subject: Re: Index not being used in MAX function (7.2.3)