Re: using sequences

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Erik Price <eprice(at)ptc(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: using sequences
Date: 2003-06-14 12:21:24
Message-ID: 20030614122124.GA27374@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jun 13, 2003 at 17:29:01 -0400,
Erik Price <eprice(at)ptc(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2003-06-14 13:27:20 Re: Index not being used in MAX function (7.2.3)
Previous Message Jason Godden 2003-06-14 08:57:42 Growing Database Size Solved