pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: liam@morland.ca <liam@morland.ca>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #18151: pg_upgradecluster fails when column default refers to column
Date: Mon, 09 Oct 2023 11:03:37 -0400
Message-ID: <143483.1696863817@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwa8=RVgMFLVuyC7izD5-OaBMRhN_kjg7+fiD3GY3ivo1A@mail.gmail.com>
References: <18151-cdc2191b130172c7@postgresql.org>
	<CAKFQuwa8=RVgMFLVuyC7izD5-OaBMRhN_kjg7+fiD3GY3ivo1A@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sunday, October 8, 2023, PG Bug reporting form <noreply@postgresql.org>
> wrote:
>> 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.

Well, you're not allowed to do it directly:

regression=# create table foo (f1 int default ((select max(f1) from foo)));
ERROR:  cannot use subquery in DEFAULT expression
LINE 1: create table foo (f1 int default ((select max(f1) from foo))...
                                         ^

but that's just a minor implementation restriction.  Doing it through
a function is fine.  (Whether it's a good idea is another question.)
Unlike, say, CHECK constraints, there's not any expectation that
a default expression be immutable or avoid dependence on database
state --- if there was, "default nextval(...)" would be problematic.

In any case, dump/restore ought not fail like this.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <143483.1696863817@sss.pgh.pa.us>
Permalink:  ../143483.1696863817@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/143483.1696863817@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, liam@morland.ca, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18151: pg_upgradecluster fails when column default refers to column
  In-Reply-To: <143483.1696863817@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox