Populate unique column with default value

Поиск
Список
Период
Сортировка
От Jon Horsman
Тема Populate unique column with default value
Дата
Msg-id 4f4c2a010710010824t7a2fbd59kb9102c879b389a5d@mail.gmail.com
обсуждение исходный текст
Ответы Re: Populate unique column with default value  ("Jon Horsman" <horshaq@gmail.com>)
Re: Populate unique column with default value  ("Rodrigo De Le�" <rdeleonp@gmail.com>)
Список pgsql-sql
Hey,

I'm updating the user table in our db to have a new column "username"
as follows.
ALTER TABLE usertable ADD COLUMN username varchar(64)
UPDATE usertable SET username='<extension of current row>' WHERE username ISNULL
ALTER TABLE usertable ALTER COLUMN username SET NOT NULL
ALTER TABLE usertable ADD CONSTRAINT usertable_username_key UNIQUE(username)

I want to essentially do what i have above but need to populate the
username field with some unique value so that the last ALTER will run.I have another column in this table that is
unique,an phone
 
extension, and am hoping to use this as a default username.  Is there
an elegant way i can set the username to be the extension of the
current row or should i just write a little loop that goes threw and
populates my username with the users extension manually for each user
in my db and then run the last ALTER.

Thanks,

Jon.


В списке pgsql-sql по дате отправления:

Предыдущее
От: Luis Carlos Ferreira
Дата:
Сообщение: Re: problems with copy
Следующее
От: "Jon Horsman"
Дата:
Сообщение: Re: Populate unique column with default value