Primary Key with auto increment field

From: "x asasaxax" <xanaruto(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Primary Key with auto increment field
Date: 2008-04-01 22:43:36
Message-ID: 91495cb0804011543n7f35f880ud691fa8f30bbe505@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I would like to increment one field, depending of the value of the
other. here´s an example:

id variable
1 1
2 1
1 2
2 2

can i do that with the following commands?

SELECT setval('sequence',(SELECT max(id) FROM table)) INTO variable;
insert into table values(variable, ..., ...); ?

Will this be transactional? Cause, they say that setval is a command
that its transactional. Using this way i

don´t will need to use a sequence anymore. Is that correct?

Thanks you all.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message carty mc 2008-04-01 23:56:27 Re: dblink ,dblink_exec not participating in a Transaction??
Previous Message carty mc 2008-04-01 22:28:19 dblink ,dblink_exec not participating in a Transaction??