Re: Chicken/egg problem with range types - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Chicken/egg problem with range types
Date
Msg-id 1EA42BB9-B372-4B41-A6DD-92D3FC507999@gmail.com
Whole thread Raw
In response to Re: Chicken/egg problem with range types  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On 18 Jul 2012, at 16:15, Tom Lane wrote:

> Alban Hertroys <haramrae@gmail.com> writes:
>> On 18 Jul 2012, at 5:08, Tom Lane wrote:
>>> I wonder whether we could improve this by postponing the no-shell-types
>>> check from creation to function runtime.
>
>> I don't suppose it'd be possible to treat it as a deferred constraint? Then the check would be moved to the end of
thetransaction. 
>
> You mean, after we've already crashed, or allowed a security breach to
> happen?  Doesn't sound very helpful.  In any case, my concern is that
> there not be any added overhead, not about moving it around.


I did mean the transaction in which the dependency got created, not some later transaction in which it gets used. I'm
fairlysure that'd be before any crashes or security breaches. Or is that not what you're implying? 

Basically:
BEGIN;
CREATE TYPE dt_range AS (..., CANONICAL = dt_range_canonical); -- check for CANONICAL function deferred
CREATE FUNCTION dt_range_canonical(dt_range) ...; -- now it exists
COMMIT; -- here the check for the CANONICAL function is performed

I did make an assumption in there that the dependency doesn't get used before the creating transaction committed. Using
thedependency in the same transaction that created it should probably not be allowed, or the check should be moved to
functionruntime if that happens (like in your original suggestion). 


Another alternative, which would probably require a major effort to implement, would be to make CREATE FUNCTION
inlinable(is that the right word?) by making the DDL statement return the function identifier of the function it just
created.

With that, the dependency of the OP would be created somewhat like:

CREATE TYPE dt_range AS (..., CANONICAL = (CREATE FUNCTION dt_range_canonical(dt_range) ...));

Some languages use similar constructs, for example to assign methods to object prototypes in the case of Javascript. I
know,SQL is not object oriented (but neither is Javascript, strictly speaking). 

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.


pgsql-general by date:

Previous
From: Scott Bailey
Date:
Subject: Re: Chicken/egg problem with range types
Next
From: "Bob Pawley"
Date:
Subject: Trouble with NEW