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 1nKrtx-0000dY-DI for pgsql-general@arkaria.postgresql.org; Fri, 18 Feb 2022 01:17:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKrtu-0003Oe-Go for pgsql-general@arkaria.postgresql.org; Fri, 18 Feb 2022 01:17:34 +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 1nKrtu-0003OU-6M for pgsql-general@lists.postgresql.org; Fri, 18 Feb 2022 01:17:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nKrtq-0000aZ-V8 for pgsql-general@lists.postgresql.org; Fri, 18 Feb 2022 01:17:33 +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 21I1HP1f3781668; Thu, 17 Feb 2022 20:17:25 -0500 From: Tom Lane To: "David G. Johnston" cc: Bryn Llewellyn , Adrian Klaver , Alvaro Herrera , pgsql-general list Subject: Re: alter function/procedure depends on extension In-reply-to: References: <7C2D01B4-AD32-48DB-B5FA-6FFBC312ECB2@yugabyte.com> <4c6b69e2-52c6-359d-3ed9-04842f631ffe@aklaver.com> Comments: In-reply-to "David G. Johnston" message dated "Thu, 17 Feb 2022 17:32:31 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3781666.1645147045.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 17 Feb 2022 20:17:25 -0500 Message-ID: <3781667.1645147045@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > Maybe, but the behavior does exist but is bugged in its current state. > Whether it is advisable for users to use this feature is immaterial, the > bug needs to be fixed so that is works as documented for those that choo= se > to do so. There is no bug here; it's operating as designed and documented. Maybe the docs need some refinement. The way this is intended to work is that if you have a function that depends on an extension -- say by using an extension-defined data type -- then the *default* behavior is that you'd have to say CASCADE in order to drop the extension. The point of the ALTER DEPENDS ON functionality is to declare that you don't want that behavior, but would like the function to go away silently (ie, without CASCADE) when the extension is dropped. Thus: test=3D# create extension cube; CREATE EXTENSION test=3D# create function myfunc(cube) returns int as 'select cube_dim($1)'= language sql; CREATE FUNCTION test=3D# drop extension cube; ERROR: cannot drop extension cube because other objects depend on it DETAIL: function myfunc(cube) depends on type cube HINT: Use DROP ... CASCADE to drop the dependent objects too. test=3D# drop extension cube cascade; NOTICE: drop cascades to function myfunc(cube) DROP EXTENSION versus test=3D# create extension cube; CREATE EXTENSION test=3D# create function myfunc(cube) returns int as 'select cube_dim($1)'= language sql; CREATE FUNCTION test=3D# alter function myfunc(cube) depends on extension cube; ALTER FUNCTION test=3D# drop extension cube; DROP EXTENSION test=3D# \df myfunc List of functions Schema | Name | Result data type | Argument data types | Type = --------+------+------------------+---------------------+------ (0 rows) That's acting as designed and we're not going to change it for fear of breaking existing use-cases. However, maybe the use of "automatic" in the documentation isn't sufficiently clear. Now, if you have a function that has some internal, not-visible-to-the-dependency-system extension dependency, it's true that you don't get any protection against that: test=3D# create extension cube; CREATE EXTENSION test=3D# create function myfunc(int) returns int as 'select cube_dim(cube(= $1,$1))' language sql; CREATE FUNCTION test=3D# drop extension cube; DROP EXTENSION However, the function wasn't dropped, so it's hard to argue that the dependency system didn't do its job. The function is still there, even though it will fail at execution: test=3D# select myfunc(42); ERROR: function cube(integer, integer) does not exist LINE 1: select cube_dim(cube($1,$1)) ^ HINT: No function matches the given name and argument types. You might ne= ed to add explicit type casts. QUERY: select cube_dim(cube($1,$1)) CONTEXT: SQL function "myfunc" during inlining You just need to re-install the extension, so it's not like you lost much: test=3D# create extension cube; CREATE EXTENSION test=3D# select myfunc(42); myfunc = -------- 1 (1 row) In any case, ALTER DEPENDS ON EXTENSION is not meant to provide protection against that scenario. The best thing we have for one-off internal dependencies right now is that new-style SQL functions do expose them: test=3D# drop function myfunc(int); DROP FUNCTION test=3D# create function myfunc(int) returns int begin atomic; select cube= _dim(cube($1,$1)); end; CREATE FUNCTION test=3D# drop extension cube; ERROR: cannot drop extension cube because other objects depend on it DETAIL: function myfunc(integer) depends on function cube(double precisio= n,double precision) HINT: Use DROP ... CASCADE to drop the dependent objects too. Another possible approach is to group such functions into their own extension, which you could make dependent on cube. regards, tom lane