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 1u5pG2-006XK9-U7 for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Apr 2025 17:12:07 +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 1u5pG0-00GfC8-Rb for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Apr 2025 17:12:05 +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 1u5pG0-00GfBz-Fe for pgsql-hackers@lists.postgresql.org; Fri, 18 Apr 2025 17:12:05 +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.96) (envelope-from ) id 1u5pFz-000jmu-01 for pgsql-hackers@lists.postgresql.org; Fri, 18 Apr 2025 17:12:04 +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 53IHC1HE2635974; Fri, 18 Apr 2025 13:12:01 -0400 From: Tom Lane To: jian he cc: pgsql-hackers@lists.postgresql.org Subject: Re: ALTER COLUMN SET DATA TYPE does not change the generation expression's collation In-reply-to: References: Comments: In-reply-to jian he message dated "Fri, 18 Apr 2025 21:05:33 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2635972.1744996321.1@sss.pgh.pa.us> Date: Fri, 18 Apr 2025 13:12:01 -0400 Message-ID: <2635973.1744996321@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk jian he writes: >> ATPrepAlterColumnType forbids us to ALTER COLUMN SET DATA TYPE USING (expr) >> for generated columns. >> however we can still change the generated column type from non-text to text >> or text type from one collation to another collation. I don't really understand why we allow SET DATA TYPE on a generated column at all. However ... >> In ATExecAlterColumnType, we also need to set the generation >> expression collation? Don't believe that would matter in the slightest. The generation expression is not exposed anywhere --- we don't incorporate it in the plan tree, just evaluate it in ExecComputeStoredGenerated. It could matter in the case of a virtual generated column, but it appears that that works already: regression=# CREATE TABLE x1(a int, b int GENERATED ALWAYS AS (a * 2) virtual, c text GENERATED ALWAYS AS ('1') stored ); CREATE TABLE regression=# insert into x1 values (11); INSERT 0 1 regression=# ALTER TABLE x1 alter column b set data type text collate "C"; ALTER TABLE regression=# select pg_collation_for(b) from x1; pg_collation_for ------------------ "C" (1 row) regression=# ALTER TABLE x1 alter column b set data type text collate "POSIX"; ALTER TABLE regression=# select pg_collation_for(b) from x1; pg_collation_for ------------------ "POSIX" (1 row) (It looks like the reason that works is that build_generation_expression inserts the necessary coercion.) So I don't see a bug here. If you want to claim that this is a bug deserving of being an open item, I think you need to demonstrate some observable misbehavior. If you want to say it'd be cleaner to fix the stored expression and get rid of the extra step in build_generation_expression, I'd probably agree, but that seems like cleanup that could wait for v19. It's certainly not a bug affecting any stable branches. regards, tom lane