Re: Changing ids conflicting with serial values?

From: Marc Boucher <pgml(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Changing ids conflicting with serial values?
Date: 2005-11-04 21:49:38
Message-ID: 27lnm1pjrs6q6dv8vv24ies8fe1s3ihutl@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 11:49 04/11/2005 -0500, Alex Turner wrote:
> I think he meant
>
> create sequence test_seq;
> select setval('test_seq',(select max(primary_key_id) from my_table));
>
> not max value of a serial type.

What I understand, and from what I know by using mysql, is that mysql
auto-adjust the max value of a serial.
Something like :
- a table with 5000 elements with ids from 1-5000.
- if you update the id in one of the rows and set it to 65000, mysql
updates the serial current value.
- even if you delete, or change the id back to its previous value, the
current value will still be 65000.
- a new inserted row will have the id 65001.

Now assuming the id's maximum value is 65535, and you set one of the rows to
this value, mysql will be unable to find a "nextval" greater than 65535. New
inserts will fail.
I don't know if it is still the case with recent versions of mysql, but that's
what I discovered while testing a web application.

Just to say that even mysql has its problems when a user plays with serial PK.

--
Marc

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2005-11-04 23:51:10 Re: Replicating databases
Previous Message Bill Bartlett 2005-11-04 20:42:20 Re: Using native win32 psql.exe using alternative cygwin terminal