Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-admin by date

Next:From: Bruno Wolff IIIDate: 2005-05-28 20:52:26
Subject: Re: Adding Serial Type
Previous:From: David PrattDate: 2005-05-28 19:18:30
Subject: Re: Adding Serial Type

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group