Re: No serial type - Mailing list pgsql-general

From Scott Marlowe
Subject Re: No serial type
Date
Msg-id dcc563d10811180937r2f97bdd6ma9f94853ffa228c@mail.gmail.com
Whole thread Raw
In response to No serial type  (Simon Connah <simon.n.connah@btopenworld.com>)
Responses Re: No serial type  (Raymond O'Donnell <rod@iol.ie>)
Re: No serial type  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: No serial type  (Christian Schröder <cs@deriva.de>)
List pgsql-general
On Tue, Nov 18, 2008 at 10:24 AM, Simon Connah
<simon.n.connah@btopenworld.com> wrote:
> Hi,
> I've just started using PostgreSQL and have been reading up on it. Part of
> what I wanted to do was to have a column which automatically incremented
> itself by one every time I do an INSERT. From reading the manual I was lead
> to believe that the correct type for this was either serial or bigserial.
> But whenever I try and update my column to this type it says that it can not
> find that data type. Am I doing something wrong?

Serial is a "pseudotype".  It represents creating an int or bigint and
a sequence then assigning a default value for the column and setting
dependency in the db so the sequence will be dropped when the table
gets dropped.  If you don't want to recreate the table, you can do
this:

create table a (i int primary key, info text);
create sequence a_i_seq;
alter table a alter column i set default nextval('a_i_seq');

not sure the alter table syntax is spot on, haven't used it in a few months.

pgsql-general by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: High Availability for PostgreSQL on Windows 2003.
Next
From: "Andrus"
Date:
Subject: Conversion of string to int using digits at beginning