Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column - Mailing list pgsql-bugs

From Feike Steenbergen
Subject Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column
Date
Msg-id CAK_s-G0eNHk_RocV2UQ3_PJaaUfUegnx4BDRnjJ4aB0x8nK0iA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Responses Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: BUG #15198: nextval() accepts tables/indexes when adding adefault to a column  (Andres Freund <andres@anarazel.de>)
List pgsql-bugs
On 16 May 2018 at 16:20, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

> In this case, they are putting the erroneous call into a column default,
> so the difference ends up being getting the error at setup time versus
> at run time, which is a difference of significance.

Yes, I'm not particularly concerned with nextval taking a regclass as
an argument, and
therefore raising this error, but I'd rather have this error at DDL
time than at DML time.

I don't know how hard it would be to implement, but say, calling
currval(regclass) when
a default is defined should already throw this error at DDL time.

Or, when registering the default in the catalog, we verify that it is
actually a sequence:

Note: I'm not a C coder, so read it as pseudo-code please.

--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -2059,6 +2059,9 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
        defobject.objectId = attrdefOid;
        defobject.objectSubId = 0;

+       if (!IsSequence( find_oid_referenced (defobject) ) )
+               elog(ERROR, "Column defaults can only depend on sequences")
+
        heap_close(adrel, RowExclusiveLock);

        /* now can free some of the stuff allocated above */

but again, I've only seen this once, so the value of adding this check
seems very limited


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15203: trigger does not recognize schema changes when passing ondata
Next
From: Kyotaro HORIGUCHI
Date:
Subject: Re: pg_ctl -D PGDATA stop -m fast gets the following message 57P03FATAL: the database system is shutting down