Re: serial properties - Mailing list pgsql-general

From Eric G. Miller
Subject Re: serial properties
Date
Msg-id 20010301225247.A26057@calico.local
Whole thread Raw
In response to serial properties  ("Martin A. Marques" <martin@math.unl.edu.ar>)
List pgsql-general
On Thu, Mar 01, 2001 at 04:49:25PM -0300, Martin A. Marques wrote:
> Hi, I would like to know which are the properties of the SERIAL type.
> Is a column defined SERIAL a primary key?
>
> Saludos... :-)

create table foo (
id serial primary key,
data text not null check(char_length(data) > 0)
);

Note: SERIAL isn't really a "type".  The data type of "id" is an integer
(oid I think??), and some hooks to use a SEQUENCE for the default value
of "id" are created (as is the SEQUENCE).  If you drop the table, you
also need to drop the sequence that "SERIAL" creates.

IMHO, automatically incremented number fields used for primary keys are
both a blessing and a curse.  It is almost always better to use some
other data that *means something* for a primary key.  If there's no
possible candidate key, *then* maybe an autonumber key is appropriate.

--
Eric G. Miller <egm2@jps.net>

pgsql-general by date:

Previous
From: Renaud Tthonnart
Date:
Subject: Re: Counting elements of an array
Next
From: Peter Vazsonyi
Date:
Subject: Triggered data change violation