Home > Archive > PostgreSQL Discussion > April 2006 > Re: Change SERIAL to INTEGER









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Change SERIAL to INTEGER
Pedro Monjo Florit

2006-04-04, 8:26 pm

Pandurangan R S wrote:
> Hi,
>
> Is there any way to change a SERIAL type to an INTEGER? I think that it
> should be easy, since SERIAL is, in fact, an INTEGER with some conditions.
>
> There serial column is just a integer, with default as nextval from a
> sequence, so there is no neccessity to change the datatype of the
> column. You have successfully removed the default value for this
> column with you first SQL statement.
>
> I hope this condition should not cause any problem, except that
> sequence lingers in the database.
>
> However, if you are determined to get rid of the sequence, then you
> may follow the procedure below
>
> Disclaimer : It worked for me and I hope that this tinkering with
> pg_depend table will not cause any adverse effects and you might want
> to make sure that there will not be any side effects and I am not
> responsible for any damage caused :)
>
> select * from pg_depend where refobjid = (select oid from pg_class
> where relname = 'mytable') and objid = (select oid from pg_class where
> relname = 'mytable_mytableid_s
eq');
>
> delete from pg_depend where refobjid = (select oid from pg_class where
> relname = 'mytable') and objid = (select oid from pg_class where
> relname = 'mytable_mytableid_s
eq');
>
> DROP SEQUENCE mytable_mytableid_se
q;
>
> Regards
> Pandu
>
> On 1/27/06, Pedro Monjo Florit <pmonjo2000@yahoo.com> wrote:

[color=darkred]

Hi Pandu,

I have finally had some time to try your suggestion and it seems to work
perfectly.

Thanks,

Pedro

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com