From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Steven Brown <swbrown(at)ucsd(dot)edu> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Changing ids conflicting with serial values? |
Date: | 2005-11-03 02:38:05 |
Message-ID: | 17183.1130985485@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Steven Brown <swbrown(at)ucsd(dot)edu> writes:
> When I change an id (primary key serial) in a table, the next value
> returned by the sequence for the id can conflict with that id (e.g.,
> change the id to be id + 1). MySQL seems to handle this transparently
> by skipping conflicting values, but with PostgreSQL I get primary key
> conflicts. It seems rather bad if a user can modify an id in a row and
> cause failures for all future inserts - it's just too fragile. What's
> the proper way to handle this in PostgreSQL?
Plan A: don't do that. Why in the world is it a good idea to modify an
artificial primary key? It's not like there's some external meaning to
the values.
Plan B: after you do it, adjust the sequence generator with setval().
You can use max() to figure out where to set the generator.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Alex Turner | 2005-11-03 03:12:31 | Re: SQL injection |
Previous Message | David Fetter | 2005-11-03 01:49:42 | Re: Data Dictionary generator? |