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 1nUBz5-0006TZ-O3 for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Mar 2022 18:33:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nUBz4-0003XM-CE for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Mar 2022 18:33:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nUBz3-0003XD-Uu for pgsql-bugs@lists.postgresql.org; Tue, 15 Mar 2022 18:33:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nUBz1-0006gv-Fk for pgsql-bugs@lists.postgresql.org; Tue, 15 Mar 2022 18:33:24 +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 22FIXK5t339143; Tue, 15 Mar 2022 14:33:20 -0400 From: Tom Lane To: kmanh999@gmail.com cc: Peter Eisentraut , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17439: DROP FUNCTION functionName(); drops associated generated column without using CASCADE In-reply-to: <17439-7df4421197e928f0@postgresql.org> References: <17439-7df4421197e928f0@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 15 Mar 2022 15:11:17 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <339141.1647369200.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 15 Mar 2022 14:33:20 -0400 Message-ID: <339142.1647369200@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: > We have the following DDL > ... > area double precision generated always as (map.area(geometr= y)) stored > If I execute `DROP FUNCTION IF EXISTS map.area(geometry)`, it should err= or > out saying it is depended on by building.area. However, instead it > successfully drops map.area(geometry) and also drops the building.area > column. Yeah. I think this might be intentional, but it's surely a POLA violation. To reproduce: regression=3D# create function foo(int) returns int as 'select $1+1' langu= age sql immutable; CREATE FUNCTION regression=3D# create table bar (x int, y int generated always as (foo(x))= stored); CREATE TABLE regression=3D# select pg_describe_object(classid,objid,objsubid) as obj, p= g_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype from pg= _depend where objid > ...; obj | ref = | deptype = -----------------------------------------+--------------------------------= ----+--------- function foo(integer) | transform for integer language = sql | n function foo(integer) | schema public = | n type bar | table bar = | i type bar[] | type bar = | i table bar | schema public = | n default value for column y of table bar | column y of table bar = | a column y of table bar | column x of table bar = | a column y of table bar | function foo(integer) = | a (8 rows) So the dependencies of the generation expression have been attached to the column itself with 'a' (automatic) deptype, which explains the behavior. But is that actually sensible? I think 'n' deptype would provide the semantics that one would expect. Maybe there is something in the SQL spec motivating references to other columns of the same table to be handled this way, but surely that's not sane for references to anything else. It also seems dubious for the default -> column deptype to be 'a' rather than 'i' for a GENERATED column. I see that we have some special-case code that prevents a direct drop: regression=3D# alter table bar alter column y drop default; ERROR: column "y" of relation "bar" is a generated column HINT: Use ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION instead. but I don't have a lot of faith that that covers all possible code paths. An 'i' dependency would make it much harder to screw this up. regards, tom lane