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 1s6uUs-002Q2k-06 for pgsql-bugs@arkaria.postgresql.org; Tue, 14 May 2024 15:55:23 +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 1s6uUr-00GiAI-Sz for pgsql-bugs@arkaria.postgresql.org; Tue, 14 May 2024 15:55:21 +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 1s6uUr-00GiA9-Kn for pgsql-bugs@lists.postgresql.org; Tue, 14 May 2024 15:55:21 +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 1s6uUp-000BJZ-9J for pgsql-bugs@lists.postgresql.org; Tue, 14 May 2024 15:55:20 +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 44EFtIgc1104766; Tue, 14 May 2024 11:55:18 -0400 From: Tom Lane To: remi.cura@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18464: Replacing a SQL function silently drops the generated columns that use this function In-reply-to: <18464-9f1edc4037b65003@postgresql.org> References: <18464-9f1edc4037b65003@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 14 May 2024 15:26:15 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1104764.1715702118.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 14 May 2024 11:55:18 -0400 Message-ID: <1104765.1715702118@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 a SQL function that I defined myself. Let's call it MyFunction(). > I use MyFunction in generated columns of 2 distinct tables. > Whe trying to delete MyFunction, the DB correctly raises an error. > However, when I `CREATE OR REPLACE` this existing function in place, the= DB > silently drop all the generated columns depending on this function. > This is not the expected behavior. Indeed not, and it does not happen like that for me: $ psql psql (14.12) Type "help" for help. regression=3D# create function testfunc(int) returns int strict immutable = language sql as 'select $1+1'; CREATE FUNCTION regression=3D# create table foo (f1 int, f2 int generated always as (testf= unc(f1)) stored); CREATE TABLE regression=3D# insert into foo values(1),(10); INSERT 0 2 regression=3D# table foo; f1 | f2 = ----+---- 1 | 2 10 | 11 (2 rows) regression=3D# create or replace function testfunc(int) returns int strict= immutable language sql as 'select $1+2'; CREATE FUNCTION regression=3D# table foo; f1 | f2 = ----+---- 1 | 2 10 | 11 (2 rows) Now you could make a reasonable argument that the generated column should have auto-updated. We don't implement that (at least not yet), on the grounds that what I did above broke the function's promise of immutability. The same change would also have broken indexes using the function, so generated columns are not any worse. In any case, please provide a self-contained example demonstrating your claim. regards, tom lane