Re: Adding Serial Type - Mailing list pgsql-admin

From John DeSoi
Subject Re: Adding Serial Type
Date
Msg-id 183b3bdba4539903b1a778f815f6aa43@pgedit.com
Whole thread Raw
In response to Adding Serial Type  (David Pratt <fairwinds@eastlink.ca>)
List 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


pgsql-admin by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Adding Serial Type
Next
From: Bruno Wolff III
Date:
Subject: Re: Adding Serial Type