Skip site navigation (1) Skip section navigation (2)

Re: [SQL] How to Convert Integer to Serial

From: Shoaib Mir <shoaibmir(at)gmail(dot)com>
To: venkat <ven(dot)tammineni(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] How to Convert Integer to Serial
Date: 2010-10-29 05:00:16
Message-ID: AANLkTik2hgCmweE39jemA6p4xPUjh8Gv_QsWdT7uL5UV@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-sql
On Fri, Oct 29, 2010 at 3:48 PM, venkat <ven(dot)tammineni(at)gmail(dot)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/

In response to

Responses

pgsql-sql by date

Next:From: Shoaib MirDate: 2010-10-29 05:01:40
Subject: Re: [SQL] How to Convert Integer to Serial
Previous:From: venkatDate: 2010-10-29 04:58:24
Subject: Re: How to Convert Integer to Serial

pgsql-general by date

Next:From: Shoaib MirDate: 2010-10-29 05:01:40
Subject: Re: [SQL] How to Convert Integer to Serial
Previous:From: John R PierceDate: 2010-10-29 04:58:53
Subject: Re: Adivice on master - master replication.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group