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 1ron0w-003MtI-51 for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2024 16:17:34 +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 1ron0u-005iNH-KE for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2024 16:17:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ron0u-005iN9-C3 for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2024 16:17:32 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ron0n-006MTd-Hd for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2024 16:17:31 +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 42PGHPbB2497749; Mon, 25 Mar 2024 12:17:25 -0400 From: Tom Lane To: vidushi2504@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18407: ALTER TABLE SET SCHEMA on foreign table with SERIAL column does not move sequence to new schema In-reply-to: <18407-4fd07373d252c6a0@postgresql.org> References: <18407-4fd07373d252c6a0@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 25 Mar 2024 14:50:53 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2497747.1711383445.1@sss.pgh.pa.us> Date: Mon, 25 Mar 2024 12:17:25 -0400 Message-ID: <2497748.1711383445@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 created a foreign table with a serial column and then moved the table to a > different schema. The sequence bound to the table column wasn't moved to the > new schema. I expected the sequence to be moved as well just like it works > for regular tables. Hmm ... that does seem fairly inconsistent. It looks like the cause is in AlterTableNamespaceInternal: /* Fix other dependent stuff */ if (rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_MATVIEW || rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) { AlterIndexNamespaces(classRel, rel, oldNspOid, nspOid, objsMoved); AlterSeqNamespaces(classRel, rel, oldNspOid, nspOid, objsMoved, AccessExclusiveLock); AlterConstraintNamespaces(RelationGetRelid(rel), oldNspOid, nspOid, false, objsMoved); } It's probably reasonable to have this relkind gating for AlterIndexNamespaces, although I'm not sure it saves much to skip that, either. But we can have sequences attached to foreign tables, and I think maybe constraints as well. Maybe it'd be best to just drop this relkind check altogether? regards, tom lane