Re: BUG #15198: nextval() accepts tables/indexes when adding a default to a column

From: Feike Steenbergen <feikesteenbergen(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15198: nextval() accepts tables/indexes when adding a default to a column
Date: 2018-05-17 06:41:53
Message-ID: CAK_s-G0eNHk_RocV2UQ3_PJaaUfUegnx4BDRnjJ4aB0x8nK0iA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 16 May 2018 at 16:20, Peter Eisentraut
<peter(dot)eisentraut(at)2ndquadrant(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2018-05-17 08:00:21 Re: pg_ctl -D PGDATA stop -m fast gets the following message 57P03 FATAL: the database system is shutting down
Previous Message PG Bug reporting form 2018-05-16 21:06:30 BUG #15203: trigger does not recognize schema changes when passing on data