From: Tom Lane <tgl@sss.pgh.pa.us>
To: reshkekirill@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19023: Table DDL default column expression depending on temp objects
Date: Mon, 18 Aug 2025 10:05:55 -0400
Message-ID: <347682.1755525955@sss.pgh.pa.us> (raw)
In-Reply-To: <19023-0a5a85a44ec3f0c6@postgresql.org>
References: <19023-0a5a85a44ec3f0c6@postgresql.org>
PG Bug reporting form <noreply@postgresql.org> writes:
> I have found two cases when user can define a relation, which has temp
> objects in its DEFAULT expression.
> First example is:
> ```
> reshke=# create temp sequence s1;
> CREATE SEQUENCE
> reshke=# create table tt(i int default nextval('s1'));
> CREATE TABLE
> ```
Appears to me to operate as intended: the DEFAULT will be dropped
at session exit, just as if you'd done DROP SEQUENCE s1 CASCADE.
> I think it is a bug that PostgreSQL allows this DDL to successfully
> complete.
Why?
> reshke=# create temp table x();
> CREATE TABLE
> reshke=# create table y (i int default nextval('x'));
> CREATE TABLE
> reshke=# insert into y default values ;
> ERROR: cannot open relation "x"
> DETAIL: This operation is not supported for tables.
This is not about whether x is temp or not, it's about whether
it's a sequence or not. The argument of nextval() is declared
as regclass, so we can verify that the constant is the name
of a relation; but the parser has no way to know that it ought
to be a sequence in particular.
> WDYT? Is this indeed a bug?
No. Sure, in a perfect world we could detect "it's not a sequence" at
parse time, but I can't see inventing "regsequence" just to improve
that.
regards, tom lane
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, reshkekirill@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19023: Table DDL default column expression depending on temp objects
In-Reply-To: <347682.1755525955@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