Re: change data type int4 to serial

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Seb <spluque(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: change data type int4 to serial
Date: 2007-02-21 20:47:27
Message-ID: 20070221204727.GA25540@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Feb 21, 2007 at 11:20:38 -0600,
Seb <spluque(at)gmail(dot)com> wrote:
>
> Checking the results in pgadmin, this proceeded fine, but now that I want
> to specify the primary and foreign keys in the tables, I see that the
> columns needed for this were imported as int4 data type. I would like
> these to be automatically sequenced, so need them to be 'serial'. Going
> into "properties" for these columns in pgadmin, the 'serial' option is not
> available in the "data type" pull-down menu. Is this not possible? Can
> the 'serial' data type be specified during import. Thanks in advance.

'serial' is a psuedo type that uses a DEFAULT that references a SEQUENCE.
In recent versions of postgres a dependency is set up so that you can't
delete the sequence while it is being referenced.

You can create the sequence manually, set an appropiate starting value and
use ALTER TABLE to change the default for the column to use nextval to
get the next sequence value.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ben 2007-02-21 20:51:00 Re: Quering 4 or more physicale different PostgreSQL server at once
Previous Message Brandon Aiken 2007-02-21 20:23:57 Re: postgresql vs mysql