Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

7.4 serial not working ?

0 views
Skip to first unread message

vertigo

unread,
Jul 2, 2004, 6:23:30 AM7/2/04
to
Hello
i upgraded postgresql from 7.3 to 7.4 and noticed that SERIAL
exists but does not working. Example:
My table:
create table1(
id SERIAL,
name VARCHAR(100)
);

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

Tony Reina

unread,
Jul 5, 2004, 3:53:14 PM7/5/04
to
vertigo <no...@microsoft.com> wrote in message news:<cc3d60$j71$2...@atlantis.news.tpi.pl>...

> 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

0 new messages