By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,751 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,751 IT Pros & Developers. It's quick & easy.

7.4 serial not working ?

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
vertigo <no**@microsoft.com> wrote in message news:<cc**********@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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.