Should we support new definition for Identity column : GENERATED BY DEFAULT ON NULL? - Mailing list pgsql-hackers

From Himanshu Upadhyaya
Subject Should we support new definition for Identity column : GENERATED BY DEFAULT ON NULL?
Date
Msg-id CAPF61jDWov1wubxXPOKKcsrvU6vuzmGg0581bZmSFwYW+3ybdg@mail.gmail.com
Whole thread Raw
Responses Re: Should we support new definition for Identity column : GENERATED BY DEFAULT ON NULL?
List pgsql-hackers
Hi,

Trying to insert NULL value to the Identity column defined by "GENERATED BY DEFAULT" is disallowed, but there can be use cases where the user would like to have an identity column where manual NULL insertion is required(and it should not error-out by Postgres).

How about having a new type for the Identity column as "GENERATED BY DEFAULT ON NULL", which will allow manual NULL insertion and internally NULL value will be replaced by Sequence NextValue?

ORACLE is supporting this feature by having a similar Identity column type as below:
=======================================================================
SQL> CREATE TABLE itest1 (id1 INTEGER GENERATED BY DEFAULT ON NULL
AS IDENTITY, id2 INTEGER);

Table created.

SQL> INSERT INTO itest1 VALUES (NULL, 10);    --Supported with GENERATED BY DEFAULT ON NULL

1 row created.

SQL> INSERT INTO itest1 VALUES (1,30);

1 row created.

SQL> INSERT INTO itest1 (id2) VALUES (20);

1 row created.

SQL> SELECT * FROM itest1;

       ID1        ID2
---------- ----------
         1         10
         1         30
         2         20
================================================================

I think it is good to have support for GENERATED BY DEFAULT ON NULL in Postgres.

Thoughts?

Thanks,
Himanshu

pgsql-hackers by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: Error "initial slot snapshot too large" in create replication slot
Next
From: Ekaterina Sokolova
Date:
Subject: Re: RFC: Logging plan of the running query