From: | Jason Hihn <jhihn(at)paytimepayroll(dot)com> |
---|---|
To: | cristi <cristi(at)dmhi(dot)ct(dot)ro>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: currval/sequence |
Date: | 2003-08-15 13:01:57 |
Message-ID: | NGBBLHANMLKMHPDGJGAPOEGICMAA.jhihn@paytimepayroll.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Nabil Sayegh | 2003-08-15 13:41:54 | Re: currval/sequence |
Previous Message | Aled Morris | 2003-08-15 12:38:31 | using procedural languages... |