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

Re: Adding Serial Type

From: David Pratt <fairwinds(at)eastlink(dot)ca>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Adding Serial Type
Date: 2005-05-28 19:18:30
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
On Saturday, May 28, 2005, at 03:27 PM, Bruno Wolff III wrote:

> On Sat, May 28, 2005 at 14:27:17 -0300,
>   David Pratt <fairwinds(at)eastlink(dot)ca> wrote:
>> Pretty basic question. Is it necessary to add NOT NULL or UNIQUE NOT
>> NULL to SERIAL or is this implicit and unnecessary?
> Serials no longer generate a uniqie index by default. So in practice
> you will normally want to declare them as PRIMARY KEYs. However there
> are cases where you don't need this and the index is extra overhead.

Alright.  so would it be better form for me to to this in a 

CREATE TABLE new_table (
	id                             SERIAL,
	description             TEXT NOT NULL

And then in a create_primary_keys.sql do this for the tables requiring 

ALTER TABLE new_table ADD CONSTRAINT new_table_pkey PRIMARY KEY (id);

Does the PRIMARY KEY declaration ensure that the id values are unique? 
Serial should always give me an incremented value that's different so I 
am assuming it is  unnecessary to use UNIQUE.  Am I correct?


In response to


pgsql-admin by date

Next:From: John DeSoiDate: 2005-05-28 20:35:57
Subject: Re: Adding Serial Type
Previous:From: Bruno Wolff IIIDate: 2005-05-28 18:27:54
Subject: Re: Adding Serial Type

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