Serial and NULL values - Mailing list pgsql-hackers

From Bruce Momjian
Subject Serial and NULL values
Date
Msg-id 199910292129.RAA13358@candle.pha.pa.us
Whole thread Raw
Responses Re: [HACKERS] Serial and NULL values  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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'CREATEtest=>insert into test (x) values (100);INSERT 19359 1test=> 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 ytest=>
insertinto test  values (100, 0);INSERT 19363 1test=> insert into test  values (100, 0);ERROR:  Cannot insert a
duplicatekey 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@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] view vs. inheritance hierarchy (was: Bug(?) in pg_get_ruledef())
Next
From: "G. Anthony Reina"
Date:
Subject: MATLAB PostgreSQL interface