Re: Change the behaviour of the SERIAL "Type" - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: Change the behaviour of the SERIAL "Type"
Date
Msg-id 20030626124929.GA7040@wolff.to
Whole thread Raw
In response to Change the behaviour of the SERIAL "Type"  (Dani Oderbolz <oderbolz@ecologic.de>)
Responses Re: Change the behaviour of the SERIAL "Type"
List pgsql-sql
On Thu, Jun 26, 2003 at 14:31:34 +0200, Dani Oderbolz <oderbolz@ecologic.de> wrote:
> 
> It was written for MySQL, which can take NULL and then assign an 
> auto_increment.
> However, in PostgreSQL I am getting problems, because it would not let 
> me insert NULL
> into a NOT NULL column (which is perfectly sensible from my point of view).
> But as the author has also left out the column list in the insert, its 
> really tedious to change
> the code.

You can use the keyword DEFAULT instead of NULL and it will do what you
want.

> This way, there would be no possibility to circumvent the Value which 
> comes from the Sequence.

You can use a unique constraint to enforce uniqueness.

> Is there a way to change SERIAL this way?

Well you can certainly write your own trigger to do this.


pgsql-sql by date:

Previous
From: Dani Oderbolz
Date:
Subject: Change the behaviour of the SERIAL "Type"
Next
From: Richard Huxton
Date:
Subject: Re: Join or Where?