Should we support new definition for Identity column : GENERATED BY DEFAULT ON NULL?

From: Himanshu Upadhyaya <upadhyaya(dot)himanshu(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Should we support new definition for Identity column : GENERATED BY DEFAULT ON NULL?
Date: 2021-11-02 11:19:57
Message-ID: CAPF61jDWov1wubxXPOKKcsrvU6vuzmGg0581bZmSFwYW+3ybdg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ekaterina Sokolova 2021-11-02 11:32:59 Re: RFC: Logging plan of the running query
Previous Message Dilip Kumar 2021-11-02 11:10:39 Re: Error "initial slot snapshot too large" in create replication slot