insert into table1 (name) values('name1');
ERROR: duplicate key violates unique constraint "table1_pkey"
Why ? I want to have autoincrementation. I do not know (when i insert
record) what id values should it have.
How can i solve this problem ?
Thanx
Michal
> Why ? I want to have autoincrementation. I do not know (when i insert
> record) what id values should it have.
> How can i solve this problem ?
No problem on my machine with 7.4.2.
testdb=# create table table1(
testdb(# id SERIAL,
testdb(# name VARCHAR(100)
testdb(# );
NOTICE: CREATE TABLE will create implicit sequence "table1_id_seq"
for "serial" column "table1.id"
CREATE TABLE
testdb=# insert into table1 (name) values('name1');
INSERT 16027587 1
testdb=# insert into table1 (name) values('name1');
INSERT 16027588 1
testdb=# insert into table1 (name) values('name2');
INSERT 16027589 1
testdb=# insert into table1 (name) values('name1');
INSERT 16027590 1
testdb=# select * from table1;
id | name
----+-------
1 | name1
2 | name1
3 | name2
4 | name1
(4 rows)
testdb=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 7.4.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC)
3.3.2 20031022 (Red Hat Linux 3.3.2-1)
(1 row)
-Tony