From: Markus Bertheau <twanger@bluetwanger.de>
To: Hunter, Ray <rhunter@enterasys.com>
Cc: postgres sql list <pgsql-sql@postgresql.org>
Subject: Re: Sequences
Date: 11 Feb 2002 15:22:30 +0100
Message-ID: <1013437356.3653.28.camel@entwicklung01.cenes.de> (raw)
In-Reply-To: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com>
References: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com>
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
Attachments:
signature.asc (application/pgp-signature, 231B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: twanger@bluetwanger.de, rhunter@enterasys.com
Subject: Re: Sequences
In-Reply-To: <1013437356.3653.28.camel@entwicklung01.cenes.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox