Re: [SQL] How to Convert Integer to Serial

Поиск
Список
Период
Сортировка
От venkat
Тема Re: [SQL] How to Convert Integer to Serial
Дата
Msg-id AANLkTimQSj4SrgtEEngEwq4eHFr1sRi5OgVnJvUhO1s9@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [SQL] How to Convert Integer to Serial  (Shoaib Mir <shoaibmir@gmail.com>)
Список pgsql-general
ohhh,, sorry... It was wrong post..sorry again...

On Fri, Oct 29, 2010 at 10:30 AM, Shoaib Mir <shoaibmir@gmail.com> wrote:
On Fri, Oct 29, 2010 at 3:48 PM, venkat <ven.tammineni@gmail.com> wrote:
Dear All,

  I want to convert integer datatype to serial datatype.. is that possible.Please let me know.


I don't think ALTER TABLE will let you do that... so the best way to achieve the same is:

- Create a sequence for the column (set the start of sequence according to the values you got already in the column)
- Now set this sequence as the default value for that specific column which you need to ALTER like this:

ALTER TABLE tablename ALTER COLUMN columnname 
        SET DEFAULT nextval('newsequence'::regclass);

--
Shoaib Mir
http://shoaibmir.wordpress.com/

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

Предыдущее
От: Shoaib Mir
Дата:
Сообщение: Re: [SQL] How to Convert Integer to Serial
Следующее
От: John R Pierce
Дата:
Сообщение: Re: How to Convert Integer to Serial