View Full Version : Serial column problem
| Why after expicitly inserting values into a serial collumn
my sequence for SERIAL column not updated ?
Here is my code:
CREATE TABLE tmp (id SERIAL, name varchar(100) NOT NULL);
insert into tmp values (1, '11111111111');
insert into tmp (name) values ('22222222');
select * from tmp;
drop table tmp;
drop sequence tmp_id_seq;
After executing this query:
insert into tmp (name) values ('22222222');
I get error:
'Cannot insert a duplicate key into unique index tmp_id_key' |
because it should be nextval('tmp_id_seq')
| Let's examine these 2 rows
insert into tmp values (1, '11111111111');
Irt insert into field id the value 1
THE SEQUENCE IS NOT AFFECTED
insert into tmp (name) values ('22222222');
if you try this query
the sequence will be affected and try to
insert the following:
insert into tmp(id,name) values(1,'22222222');
if you have a serial do not explizit give a key or if you do so you must set teh sequence to this nuber otherwise this error will occur |
vBulletin v3.5.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.