Re: BUG #18151: pg_upgradecluster fails when column default refers to column - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #18151: pg_upgradecluster fails when column default refers to column
Date
Msg-id CAKFQuwa8=RVgMFLVuyC7izD5-OaBMRhN_kjg7+fiD3GY3ivo1A@mail.gmail.com
Whole thread Raw
In response to BUG #18151: pg_upgradecluster fails when column default refers to column  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18151: pg_upgradecluster fails when column default refers to column
List pgsql-bugs
On Sunday, October 8, 2023, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      18151
Logged by:          Liam Morland
Email address:      liam@morland.ca
PostgreSQL version: 15.4
Operating system:   Debian
Description:       

I was trying to upgrade to PG 16:
pg_upgradecluster 15 main

I got this error:
pg_restore: error: could not execute query: ERROR:  relation "event" does
not exist

The reason is the the default value for column "event_id" of table "event"
is "event_id_nextval()". That function is:
SELECT COALESCE(MAX(event_id) + 1, 1) FROM event;

You are expressly forbidden to have the default value expression of a column reference a subquery. You must use a trigger.  The failure to prevent the exoressions creation or consistently report such a failure is the bug, not this.  Unfortunately preventing the behavior is not reasonable, we can only document its forbiddance.

David J.

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #18151: pg_upgradecluster fails when column default refers to column
Next
From: Tom Lane
Date:
Subject: Re: BUG #18151: pg_upgradecluster fails when column default refers to column