Unix Technical Forum

Convert serial column to regular integer

This is a discussion on Convert serial column to regular integer within the pgsql Sql forums, part of the PostgreSQL category; --> I have a need to convert an incorrectly typed serial column to a regular integer column. Basically this just ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 03:24 PM
Collin Peters
 
Posts: n/a
Default Convert serial column to regular integer

I have a need to convert an incorrectly typed serial column to a
regular integer column. Basically this just involves removing the
sequence. I am able to successfully remove the default value (DROP
DEFAULT) (which seems to use nextval) and now pgadmin does show the
column as an integer, but I cannot remove the sequence as it says it
is still in use. If I look at the column in pgadmin the sequence
field is still filled in with the sequence but it is grayed out. Is
there any way to remove the sequence fully?

Regards,
Collin

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 03:24 PM
=?ISO-8859-1?Q?Rodrigo_De_Le=F3n?=
 
Posts: n/a
Default Re: Convert serial column to regular integer

On 5/11/07, Collin Peters <cadiolis@gmail.com> wrote:
> I have a need to convert an incorrectly typed serial column to a
> regular integer column. Basically this just involves removing the
> sequence. I am able to successfully remove the default value (DROP
> DEFAULT) (which seems to use nextval) and now pgadmin does show the
> column as an integer, but I cannot remove the sequence as it says it
> is still in use. If I look at the column in pgadmin the sequence
> field is still filled in with the sequence but it is grayed out. Is
> there any way to remove the sequence fully?
>
> Regards,
> Collin


CREATE TABLE dtab (i SERIAL);

ALTER TABLE dtab ALTER COLUMN i DROP DEFAULT;

ALTER SEQUENCE dtab_i_seq OWNED BY NONE;

DROP SEQUENCE dtab_i_seq;

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 03:24 PM
Collin Peters
 
Posts: n/a
Default Re: Convert serial column to regular integer

Anything pre-8.2?

On 5/11/07, Rodrigo De León <rdeleonp@gmail.com> wrote:
>
> CREATE TABLE dtab (i SERIAL);
>
> ALTER TABLE dtab ALTER COLUMN i DROP DEFAULT;
>
> ALTER SEQUENCE dtab_i_seq OWNED BY NONE;
>
> DROP SEQUENCE dtab_i_seq;
>


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 03:24 PM
Tom Lane
 
Posts: n/a
Default Re: Convert serial column to regular integer

"=?ISO-8859-1?Q?Rodrigo_De_Le=F3n?=" <rdeleonp@gmail.com> writes:
> On 5/11/07, Collin Peters <cadiolis@gmail.com> wrote:
>> Is there any way to remove the sequence fully?


> ALTER SEQUENCE dtab_i_seq OWNED BY NONE;


Pre-8.2 that command doesn't exist, but you can get the same effect if
you manually remove the pg_depend entry that links the sequence to the
column. Be sure you're removing the right entry ;-)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:11 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com