From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | "Hunter, Ray" <rhunter(at)enterasys(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Sequences |
Date: | 2002-02-11 14:36:51 |
Message-ID: | 20020211143651.GA4020@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, Feb 11, 2002 at 08:43:23AM -0500,
"Hunter, Ray" <rhunter(at)enterasys(dot)com> 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' );
I think you want to use nextval in this context. currval is used when you
have already gotten a new sequence number and want to use it in several
inserts in the same transaction.
If you make user_id a serial type, then its default value will be nextval
and you could use:
insert into users ( "user_fname", "user_lname", "user_email" )
values ('Ray', 'Hunter', 'rhunter(at)enterasys(dot)com' );
to add a row.
From | Date | Subject | |
---|---|---|---|
Next Message | Unnikrishnan Menon | 2002-02-11 15:07:21 | Oracle "Jobs" in PostgreSQL |
Previous Message | Markus Bertheau | 2002-02-11 14:22:30 | Re: Sequences |