Re: Changing a table column datatype
От | Oliver Elphick |
---|---|
Тема | Re: Changing a table column datatype |
Дата | |
Msg-id | 1052801972.18710.33.camel@linda.lfix.co.uk обсуждение исходный текст |
Ответ на | Changing a table column datatype (<marshall@perilith.com>) |
Список | pgsql-novice |
On Tue, 2003-05-13 at 01:18, marshall@perilith.com wrote: > Hello, > > This has been asked before, but the responses weren't clear enough > for me to understand. > > I have a table `mytable' with an attribute `mycol' of datatype char(4) and > I'd like to change it to varchar(20). Mycol is populated by two values - > NULLs and four element chars. What I've tried thusfar: > > db=> ALTER TABLE mytable ADD COLUMN mycol_new VARCHAR(20); > ALTER TABLE > db=> INSERT INTO mytable (mycol_new) SELECT mycol FROM mytable; > ERROR: ExecInsert: Fail to add null value in not null attribute fqdn > > The `fqdn' attribute is another column in mytable. > > So is it the case that INSERT doesn't like inserting NULL values? Is > there another way to do this? INSERT inserts new rows and all constraints for the row must be satisfied; use UPDATE to alter existing rows. UPDATE mytable SET mycol_new = mycol; (no WHERE clause, because you want to change every row). -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "Watch ye and pray, lest ye enter into temptation. The spirit truly is ready, but the flesh is weak." Mark 14:38
В списке pgsql-novice по дате отправления: