Re: How to Convert Integer to Serial - Mailing list pgsql-sql

From Shoaib Mir
Subject Re: How to Convert Integer to Serial
Date
Msg-id AANLkTik2hgCmweE39jemA6p4xPUjh8Gv_QsWdT7uL5UV@mail.gmail.com
Whole thread Raw
In response to How to Convert Integer to Serial  (venkat <ven.tammineni@gmail.com>)
Responses Re: How to Convert Integer to Serial  (venkat <ven.tammineni@gmail.com>)
List pgsql-sql
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-sql by date:

Previous
From: venkat
Date:
Subject: Re: How to Convert Integer to Serial
Next
From: Shoaib Mir
Date:
Subject: Re: How to Convert Integer to Serial