Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q95hb-00042R-FN for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Jun 2023 15:12:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q95ha-0000ab-7K for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Jun 2023 15:12:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q95hZ-0000aP-VI for pgsql-bugs@lists.postgresql.org; Tue, 13 Jun 2023 15:12:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q95hX-0029ZE-9l for pgsql-bugs@lists.postgresql.org; Tue, 13 Jun 2023 15:12:57 +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 35DFCpWO1636675; Tue, 13 Jun 2023 11:12:51 -0400 From: Tom Lane To: pgp@gmx.it cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17970: FEATURE REQUEST-allow re-adding GENERATED ALWAYS AS constraint to existing columns after removing it In-reply-to: <17970-63daec21cbb50126@postgresql.org> References: <17970-63daec21cbb50126@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 13 Jun 2023 13:45:55 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1636673.1686669171.1@sss.pgh.pa.us> Date: Tue, 13 Jun 2023 11:12:51 -0400 Message-ID: <1636674.1686669171@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: > From what I know, it is possible to transform a GENERATED ALWAYS AS .. > STORED column into a normal one, by using: > ALTER TABLE items ALTER COLUMN transformed_id DROP EXPRESSION; > But the reverse (i.e. re-adding the "GENERATED ALWAYS AS .. STORED" part to > an existing column) is not possible. Just drop the column and re-add it. The system would have to recompute all the entries anyway, so I can't get excited about offering a shortcut. > I think this is a contradiction, because, by modifying the underlying > function, I am able to insert incoherent values in the generated column, As David mentioned, that is not considered a supported thing. We cannot enforce it (look up the "halting problem" sometime), but if you change an immutable function's behavior then ensuing problems are your fault not Postgres'. regards, tom lane