dbTalk Databases Forums  

7.4: serial not working ?

comp.databases.postgresql.bugs comp.databases.postgresql.bugs


Discuss 7.4: serial not working ? in the comp.databases.postgresql.bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
vertigo
 
Posts: n/a

Default 7.4: serial not working ? - 07-02-2004 , 05:24 AM






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


Reply With Quote
  #2  
Old   
Gaetano Mendola
 
Posts: n/a

Default Re: 7.4: serial not working ? - 07-03-2004 , 09:54 AM






vertigo wrote:

Quote:
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 ?
when you define the serial it start from 1. If you filled that table
specifing also the serial value then the serial was not incremented,
in order to solve your problem setting the serial value equal to
max(id)+1 in that table.



Regards
Gaetano Mendola






Reply With Quote
  #3  
Old   
Oliver Elphick
 
Posts: n/a

Default Re: 7.4: serial not working ? - 07-08-2004 , 12:23 PM



On Fri, 2004-07-02 at 11:24, vertigo wrote:
Quote:
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 ?
You already have rows in that table, and the sequence is generating a
key which already exists. This is not MySQL!

To cure this, set the sequence to the highest value in the table and
don't insert explicit values for that column:

SELECT setval('table1_id_seq', (SELECT MAX(id) FROM table1));

(or something like that).


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.