Bug in create operator and/or initdb
Bug in create operator and/or initdb
От:
"John Hansen" <john@geeknet.com.au>
Дата:
The following seems to me a bug in either initdb or create operator:
CREATE FUNCTION my_func (inet, inet) as '$libdir/my_func.so' LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OPERATOR <<< (PROCEDURE = my_func,LEFTARG = cidr,RIGHTARG = cidr,RESTRICT = contsel,JOIN = contjoinsel
);
ERROR: function my_func(cidr, cidr) does not exist
Now, if you look at the catalog, and the < (less than operator) as an example you will see that:
Two operators are defined for < - one for inet,inet and another for cidr,cidr.
Only one function exists named network_lt, and is declared as taking (inet,inet) as arguments.
Obviously, it should either have a corresponding function declaration, or it should be possible to create the operators using a binary compatible function (eg: where a binary compatible cast exists).
I propose, that the create operator syntax be modified to accept:
PROCEDURE = function_name (type{,type})
and that checks be made for the existence of binary compatible casts between the two (four) types.
Kind Regards,
John
Re: Bug in create operator and/or initdb
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"John Hansen" writes: > CREATE FUNCTION my_func (inet, inet) as '$libdir/my_func.so' LANGUAGE 'C' IMMUTABLE STRICT; > CREATE OPERATOR <<< ( > PROCEDURE = my_func, > LEFTARG = cidr, > RIGHTARG = cidr, > RESTRICT = contsel, > JOIN = contjoinsel > ); > ERROR: function my_func(cidr, cidr) does not exist Right ... > Now, if you look at the catalog, and the < (less than operator) as an example you will see that: > Two operators are defined for < - one for inet,inet and another for cidr,cidr. > Only one function exists named network_lt, and is declared as taking (inet,inet) as arguments. My opinion is that this is a very bogus shortcut in the network datatype code. There are no cases outside the inet/cidr group where an operator doesn't exactly match its underlying function. (The whole business of inet and cidr being almost but not quite the same type is maldesigned anyway...) The right solution for you is to declare two SQL functions. Whether you make them point at the same underlying C code is up to you. regards, tom lane
Re: Bug in create operator and/or initdb
От:
"John Hansen" <john@geeknet.com.au>
Дата:
> My opinion is that this is a very bogus shortcut in the > network datatype code. There are no cases outside the > inet/cidr group where an operator doesn't exactly match its > underlying function. (The whole business of inet and cidr > being almost but not quite the same type is maldesigned > anyway...) > > The right solution for you is to declare two SQL functions. > Whether you make them point at the same underlying C code is > up to you. Right,... In that case may I suggest fixing the catalog so network_* functions exists for both datatypes! Anything less I'd consider inconsistent... Kind regards, John
Re: Bug in create operator and/or initdb
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"John Hansen" writes: > In that case may I suggest fixing the catalog so network_* functions exists for both datatypes! Redesigning the inet/cidr distinction is on the to-do list (though I'm afraid not very high on the list). ISTM it should either be one type with a distinguishing bit in the runtime representation, or two types with no such bit needed. Having both is a schizophrenic design. It's led directly to bugs in the past, and I think there are still some corner cases that act oddly (see the archives). regards, tom lane