Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: currval/sequence



What is it that you want to do?

You don't have to manually insert the values of the sequence.
create table test1(i char(1), s serial);
insert into test 1 values ('a');
select currval('test1_seq');  <- should return 1
insert into test 1 values ('b');
select currval('test1_seq');  <- should return 2

and the tuples should be:
a | s
-----
a | 1
b | 2

In my code, I wrap it in a transaction for peace of mind. Tom (or anyone),
is that necessary? If nothing else is happening on that connection between
the insert and the select?

Hope that helps.

> -----Original Message-----
> From: pgsql-novice-owner(at)postgresql(dot)org
> [mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of cristi
> Sent: Friday, August 15, 2003 5:23 AM
> To: pgsql-novice(at)postgresql(dot)org
> Subject: [NOVICE] currval/sequence
>
>
> What is wrong here?
>
> insert into table_name (field_name) values (select
> setval('sequence_name')-1) as currval);
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
>




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group