Re: Adding Serial Type

From: John DeSoi <desoi(at)pgedit(dot)com>
To: David Pratt <fairwinds(at)eastlink(dot)ca>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Adding Serial Type
Date: 2005-05-28 20:35:57
Message-ID: 183b3bdba4539903b1a778f815f6aa43@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


On May 28, 2005, at 1:27 PM, David Pratt wrote:

> CREATE TABLE new_table (
> id SERIAL UNIQUE NOT NULL,
> description TEXT NOT NULL
> );
>
> Or should I just use below because Serial type implies this.
>
> CREATE TABLE new_table (
> id SERIAL,
> description TEXT NOT NULL
> );

The first one because it is possible for the serial to wrap around or
some other bad thing could happen if the serial is accidently reset.

But if id is really the primary key, then I would use SERIAL PRIMARY
KEY which implies UNIQUE NOT NULL. From the CREATE TABLE documentation:

The primary key constraint specifies that a column or columns of a
table may contain only unique (non-duplicate), nonnull values.
Technically, PRIMARY KEY is merely a combination of UNIQUE and NOT
NULL, but identifying a set of columns as primary key also provides
metadata about the design of the schema, as a primary key implies that
other tables may rely on this set of columns as a unique identifier
for rows.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Bruno Wolff III 2005-05-28 20:52:26 Re: Adding Serial Type
Previous Message David Pratt 2005-05-28 19:18:30 Re: Adding Serial Type