Re: Sequences

From: Markus Bertheau <twanger(at)bluetwanger(dot)de>
To: "Hunter, Ray" <rhunter(at)enterasys(dot)com>
Cc: postgres sql list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Sequences
Date: 2002-02-11 14:22:30
Message-ID: 1013437356.3653.28.camel@entwicklung01.cenes.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)enterasys(dot)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

In response to

  • Sequences at 2002-02-11 13:43:23 from Hunter, Ray

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2002-02-11 14:36:51 Re: Sequences
Previous Message James Carrier 2002-02-11 14:17:39 Re: SQL Help - multi values