Re: Sequences - Mailing list pgsql-sql

From Markus Bertheau
Subject Re: Sequences
Date
Msg-id 1013437356.3653.28.camel@entwicklung01.cenes.de
Whole thread Raw
In response to Sequences  ("Hunter, Ray" <rhunter@enterasys.com>)
List pgsql-sql
On Mon, 2002-02-11 at 14:43, Hunter, Ray wrote:
> I have various sequences in my database set up for ids.  My question is:
> How can I get the current value of the sequence without creating a session
> and using the currval function?
>
> I would like to take the current value of the sequence and use it for a
> value in an insert statement.
>
>
> Example:
>
>     insert into users ( "user_id", "user_fname", "user_lname",
> "user_email" )
>     values ( 'current sequence', 'Ray', 'Hunter',
> 'rhunter@enterasys.com' );
>

You probably wouldn't want to use the current but the next value of the
sequence. Common solution is to set the default for the column user_id
to something like
nextval(users_user_id_seq"::text)
and omit user_id in the insert statement such that the default value is
taken.

Markus Bertheau

Cenes Data GmbH


pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Sequences
Next
From: Chris Ruprecht
Date:
Subject: Re: Sequences