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 1lWpiq-0006wg-3W for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Apr 2021 00:19:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lWpip-0004OG-2h for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Apr 2021 00:19:03 +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 1lWpio-0004O9-Re for pgsql-hackers@lists.postgresql.org; Thu, 15 Apr 2021 00:19:02 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWpim-0003Yx-Fh for pgsql-hackers@lists.postgresql.org; Thu, 15 Apr 2021 00:19:02 +0000 X-Originating-IP: 79.88.149.14 Received: from [172.16.255.146] (14.149.88.79.rev.sfr.net [79.88.149.14]) (Authenticated sender: vik@postgresfriends.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 1F1EE60004; Thu, 15 Apr 2021 00:18:57 +0000 (UTC) Subject: Re: Converting contrib SQL functions to new style To: Mark Dilger Cc: Tom Lane , PostgreSQL Hackers , Peter Eisentraut , Robert Haas References: <3395418.1618352794@sss.pgh.pa.us> <3565758.1618421782@sss.pgh.pa.us> <564283e2-3ba5-54ac-1d6b-d86bef3d9dc9@postgresfriends.org> From: Vik Fearing Message-ID: <5c2edf80-d1e3-cb9a-e5a8-41f3ad59515a@postgresfriends.org> Date: Thu, 15 Apr 2021 02:18:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/15/21 12:18 AM, Mark Dilger wrote: > > >> On Apr 14, 2021, at 2:47 PM, Vik Fearing wrote: >> >> On 4/14/21 7:36 PM, Tom Lane wrote: >>> Mark Dilger writes: >>>>> On Apr 13, 2021, at 3:26 PM, Tom Lane wrote: >>>>> However I think we may still need an assumption that earthdistance >>>>> and cube are in the same schema --- any comments on that? >>> >>>> This is probably not worth doing, and we are already past feature >>>> freeze, but adding syntax to look up the namespace of an extension might >>>> help. >>> >>> Yeah, that idea was discussed before (perhaps only in private >>> security-team threads, though). We didn't do anything about it because >>> at the time there didn't seem to be pressing need, but in the context >>> of SQL function bodies there's an obvious use-case. >>> >>>> We could get something like this working just inside the CREATE EXTENSION command if we expanded on the @extschema@ idea a bit. At first I thought this idea would suffer race conditions with concurrent modifications of pg_extension or pg_namespace, but it looks like we already have a snapshot when processing the script file, so: >>> >>>> -CREATE DOMAIN earth AS cube >>>> +CREATE DOMAIN @@earthdistance@@::earth AS @@cube@@::cube >>> >>> Right, extending the @extschema@ mechanism is what was discussed, >>> though I think I'd lean towards something like @extschema:cube@ >>> to denote the schema of a referenced extension "cube". >>> >>> I'm not sure this is useful enough to break feature freeze for, >>> but I'm +1 for investigating it for v15. >> Just like we have a pseudo "$user" schema, could we have a pseudo >> "$extension" catalog? That should avoid changing grammar rules too much. >> >> CREATE TABLE unaccented_words ( >> word "$extension".citext.citext, >> CHECK (word = "$extension".unaccent.unaccent(word) >> ); > > Having a single variable $extension might help in many cases, but I don't see how to use it to handle the remaining cross-extension references, such as earthdistance needing to reference cube. Sorry, I hadn't realized that was a real example so I made up my own. Basically my idea is to use the fully qualified catalog.schema.object syntax where the catalog is a special "$extension" value (meaning we would have to forbid that as an actual database name) and the schema is the name of the extension whose schema we want. The object is then just the object. CREATE DOMAIN earth AS "$extension".cube.cube CONSTRAINT not_point check("$extension".cube.cube_is_point(value)) CONSTRAINT not_3d check("$extension".cube.cube_dim(value <= 3) ...; CREATE FUNCTION earth_box(earth, float8) RETURNS "$extension".cube.cube LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT RETURN "$extension".cube.cube_enlarge($1, gc_to_sec($2), 3); If I had my druthers, we would spell it pg_extension instead of "$extension" because I hate double-quoting identifiers, but that's just bikeshedding and has little to do with the concept itself. -- Vik Fearing