Hi all,<br /><br />Would it be possible (or reasonable) to add support for changing the type of a column to serial or
bigserial(yes, yes, I know they're not actual types)? In effect this would mean that users who forgot to set up a
sequencecould change it's type so that a new implicit sequence will be created, set with its current value set to the
highestvalue of whatever column it was bound to. This thought was triggered by a user on IRC wishing to migrate from
MySQL,but had tables with some sort of ID column without any associated sequence.<br /><br />So if you had:<br /><br
/>CREATETABLE stuff (id int, content text);<br /><br />INSERT INTO stuff (id, content) values
(1,'alpha'),(2,'beta'),(5,'gamma');<br/><br />You could just issue:<br /><br />ALTER TABLE stuff ALTER COLUMN id TYPE
serial;<br/><br />And continue as so:<br /><br />INSERT INTO stuff (content) values ('delta');<br /><br />SELECT id
fromstuff;<br /><br /> id<br />----<br /> 1<br /> 2<br /> 5<br /> 6<br />(4 rows)<br /><br />This would be instead
ofhaving to do:<br /><br />CREATE SEQUENCE id_stuff_seq;<br /><br />SELECT setval('id_stuff_seq', (SELECT max(id) FROM
stuff))<br/><br />ALTER TABLE stuff ALTER COLUMN id SET DEFAULT nextval('id_stuff_seq'::regclass);<br /><br />Which
wouldalso mean the sequence would not get dropped with the table.<br /><br />Abhorrent idea, or acceptable?<br
clear="all"/><br />-- <br />Thom Brown<br />Twitter: @darkixion<br />IRC (freenode): dark_ixion<br />Registered Linux
user:#516935<br />