Re: Remove Modifiers on Table - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: Remove Modifiers on Table
Date
Msg-id 4DD2BC92.1000403@iol.ie
Whole thread Raw
In response to Re: Remove Modifiers on Table  (Carlos Mennens <carlos.mennens@gmail.com>)
Responses Re: Remove Modifiers on Table  (Carlos Mennens <carlos.mennens@gmail.com>)
Re: Remove Modifiers on Table  (Susan Cassidy <scassidy@edgewave.com>)
List pgsql-general
On 17/05/2011 19:07, Carlos Mennens wrote:
> On Tue, May 17, 2011 at 12:57 PM, Carlos Mennens
> <carlos.mennens@gmail.com>  wrote:
>> On Tue, May 17, 2011 at 12:38 PM, Raymond O'Donnell<rod@iol.ie>  wrote:
>>> Yes, that's exactly right - SERIAL does it all for you. The mistake some
>>> people make, on the other hand, is thinking that SERIAL is a type in its own
>>> right - it's not, it just does all those steps automatically.
>
> So if I have an existing column in my table with a INT data type, I
> can't seem to understand how to convert this on my 8.4 production
> server:
>
> ALTER TABLE users ALTER COLUMN id TYPE SERIAL;
> ERROR:  type "serial" does not exist

That's because of what I just mentioned above. :-) It's not a type: it's
just a shortcut. What you need to do instead is something like this:

   -- Create the sequence.
   create sequence users_id_seq;

   -- Tell the column to pull default values from the sequence.
   alter table users alter column id set default nextval('users_id_seq');

   -- Establish a dependency between the column and the sequence.
   alter sequence users_id_seq owned by users.id;

HTH

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

pgsql-general by date:

Previous
From: Wells Oliver
Date:
Subject: Can't unsubscribe
Next
From: Carlos Mennens
Date:
Subject: Re: Remove Modifiers on Table