Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uo0Uq-00Eax4-Jj for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Aug 2025 14:06:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uo0Up-00GyOq-NG for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Aug 2025 14:06:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uo0Up-00GyOh-EK for pgsql-bugs@lists.postgresql.org; Mon, 18 Aug 2025 14:06:00 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uo0Un-000Wn7-3C for pgsql-bugs@lists.postgresql.org; Mon, 18 Aug 2025 14:05:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 57IE5txK347683; Mon, 18 Aug 2025 10:05:55 -0400 From: Tom Lane To: reshkekirill@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19023: Table DDL default column expression depending on temp objects In-reply-to: <19023-0a5a85a44ec3f0c6@postgresql.org> References: <19023-0a5a85a44ec3f0c6@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 18 Aug 2025 13:32:24 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <347681.1755525955.1@sss.pgh.pa.us> Date: Mon, 18 Aug 2025 10:05:55 -0400 Message-ID: <347682.1755525955@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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