Re: ALTER TABLE with TYPE serial does not work

From: Osvaldo Kussama <osvaldo(dot)kussama(at)gmail(dot)com>
To: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
Cc: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>, Andreas Wenk <a(dot)wenk(at)netzmeister-st-pauli(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: ALTER TABLE with TYPE serial does not work
Date: 2009-02-01 13:12:53
Message-ID: 690707f60902010512q73dacca9rccc7ebceced6e406@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/2/1 Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>:
> On Sat, Jan 31, 2009 at 9:04 PM, Richard Broersma
> <richard(dot)broersma(at)gmail(dot)com> wrote:
>> On Sat, Jan 31, 2009 at 3:16 PM, Andreas Wenk
>> <a(dot)wenk(at)netzmeister-st-pauli(dot)de> wrote:
>>
>>> Why does this not work:
>>>
>>> postgres=# ALTER TABLE tab1 ALTER COLUMN nr TYPE serial;
>>> ERROR: type "serial" does not exist
>>
>> serial is really just "short-hand" for making an integer column use
>> default incrementing function. The following will fully explain what
>> it is so that you can alter the column:
>> http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html#DATATYPE-SERIAL
>
> ... But it's probably more complicated than
> just making it a serial type, there's probably some question of
> setting the sequence according to the max value in the table. I'd be
> surprised if it's not on the TODO list somewhere.
>

Like:
SELECT setval('serial', max(id)) FROM distributors;
?

http://www.postgresql.org/docs/current/interactive/sql-createsequence.html

Osvaldo

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Russ Brown 2009-02-01 14:33:59 Re: PGSQL or other DB?
Previous Message Gerhard Heift 2009-02-01 13:05:31 Re: How to catch the id in a INSERT INTO ... RETURNING function?