Re: Chicken/egg problem with range types

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: Chicken/egg problem with range types
Дата
Msg-id 1EA42BB9-B372-4B41-A6DD-92D3FC507999@gmail.com
обсуждение исходный текст
Ответ на Re: Chicken/egg problem with range types  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Scott Bailey
Дата:
Сообщение: Re: Chicken/egg problem with range types
Следующее
От: "Bob Pawley"
Дата:
Сообщение: Trouble with NEW