Serial and NULL values

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Serial and NULL values
Date: 1999-10-29 21:29:19
Message-ID: 199910292129.RAA13358@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I just received a message from someone complaining about SERIAL/sequence. I
think there is a problem:

test=> create table test (x int, y serial);
NOTICE: CREATE TABLE will create implicit sequence 'test_y_seq' for SERIAL column 'test.y'
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'test_y_key' for table 'test'
CREATE
test=> insert into test (x) values (100);
INSERT 19359 1
test=> insert into test (x) values (100);
INSERT 19360 1

These work fine, but why does this fail:

test=> insert into test values (100, null);
ERROR: ExecAppend: Fail to add null value in not null attribute y
test=> insert into test values (100, 0);
INSERT 19363 1
test=> insert into test values (100, 0);
ERROR: Cannot insert a duplicate key into a unique index

Can't they use zero or null, and have the sequence value be computed?
Is there some design decision we made to prevent this?

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

Browse pgsql-hackers by date

  From Date Subject
Next Message G. Anthony Reina 1999-10-29 22:10:44 MATLAB PostgreSQL interface
Previous Message Tom Lane 1999-10-29 14:25:28 Re: [HACKERS] view vs. inheritance hierarchy (was: Bug(?) in pg_get_ruledef())