Re: serial properties

From: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: serial properties
Date: 2001-03-02 06:52:47
Message-ID: 20010301225247.A26057@calico.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)jps(dot)net>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jens Hartwig 2001-03-02 07:02:40 AW: AW: Addison-Wesley looking for authors
Previous Message David Wheeler 2001-03-02 06:12:34 Re: Perl & DBI/DBD::Pg confusion with finish