From: John DeSoi <desoi@pgedit.com>
To: David Pratt <fairwinds@eastlink.ca>
Cc: pgsql-admin@postgresql.org
Subject: Re: Adding Serial Type
Date: Sat, 28 May 2005 16:35:57 -0400
Message-ID: <183b3bdba4539903b1a778f815f6aa43@pgedit.com> (raw)
In-Reply-To: <BD5CCB8C-CF9D-11D9-AEE7-000A27B3B070@eastlink.ca>
References: <BD5CCB8C-CF9D-11D9-AEE7-000A27B3B070@eastlink.ca>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: desoi@pgedit.com, fairwinds@eastlink.ca
Subject: Re: Adding Serial Type
In-Reply-To: <183b3bdba4539903b1a778f815f6aa43@pgedit.com>
References: <BD5CCB8C-CF9D-11D9-AEE7-000A27B3B070@eastlink.ca> <183b3bdba4539903b1a778f815f6aa43@pgedit.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox