Feature request #14477
Add an option to create a sequence for existing integer columns
|Pull Request or Patch supplied:||No||Resolution:|
|Easy fix?:||No||Copied to github as #:||22455|
Please add an option to create a sequence for existing integer columns in the DB Manager. Changing the type to serial in the 'Field properties' dialogue isn't working.
#3 Updated by Jukka Rahkonen about 4 years ago
Can you do the same simply in PostgreSQL? I found this discussion https://www.postgresql.org/message-id/4505.1288879499%40sss.pgh.pa.us The conclusion by the developers was
We've looked at that in the past and decided there were enough corner
cases that it wasn't clearly a good idea. In particular, what do you do
with the existing data in the column? What do you do if there's already
a DEFAULT expression for the column, throw it away? In particular, what
of the special case that the column is in fact already a serial, so the
default is pointing at an existing sequence?
Making such a change to an existing table can be done manually
It feels like users should really understand what they are going to do for their database and pgSQL is just the right tool.
There are many other impossible alternatives in the Edit column-Field properties-Type drop down menu and it would be hard to analyze which changes could be done and which ones not (if data hold in bigint can fit into smallint, if varchar is plain numbers without leading zeros and could be converted into integer etc.).
The title of this issue is "Add an option to create a sequence for existing integer columns".
I would close it as Won't fix because it is not a good idea.
About the suggestion "Wouldn't it be better to remove 'serial' and 'bigserial'" I am not sure. Perhaps it would be more better to let users try and throw an uniform error message "Type could not be changed from [a] into [b]" in case of failure and list possible additional messages from the database after that.