Обсуждение: Using domains for case insensitivity

Поиск
Список
Период
Сортировка

Using domains for case insensitivity

От
Shachar Shemesh
Дата:
Hi all,

A while back I asked about creating a case insensitive postgresql. Tom, 
at the time, suggested I create a case insensitive type instead.

I am now trying to go that route, and am wondering whether domains will 
provide a shortcut for me. As far as I understand the task at hand, I am 
quite capable of using all of the existing varchar functions for input, 
output, storage, conversions and so on. The only thing I need to 
override is the comparison functions (and the resulting index creation, 
of course).

According to the docs, domains are not meant for that purpose, but for 
changing constraints of a type. Is it possible to define a domain that 
will have the same defaults and constraints as the base type, but will 
have different comparison functions? Will that provide me with what I need?
            Many thanks,
                        Shachar

-- 
Shachar Shemesh
Lingnu Open Source Consulting ltd.
http://www.lingnu.com/



Re: Using domains for case insensitivity

От
Peter Eisentraut
Дата:
Shachar Shemesh wrote:
> According to the docs, domains are not meant for that purpose, but
> for changing constraints of a type. Is it possible to define a domain
> that will have the same defaults and constraints as the base type,
> but will have different comparison functions? Will that provide me
> with what I need?

Domains constrain the allowed values of a data type and nothing more.  
If you were able to override operators, then you would create a new 
data type, thus losing a fundamental property of domains.  So this is 
not the route you want to pursue.



Re: Using domains for case insensitivity

От
Tom Lane
Дата:
Peter Eisentraut <peter_e@gmx.net> writes:
> Shachar Shemesh wrote:
>> According to the docs, domains are not meant for that purpose, but
>> for changing constraints of a type. Is it possible to define a domain
>> that will have the same defaults and constraints as the base type,
>> but will have different comparison functions? Will that provide me
>> with what I need?

> Domains constrain the allowed values of a data type and nothing more.  
> If you were able to override operators, then you would create a new 
> data type, thus losing a fundamental property of domains.  So this is 
> not the route you want to pursue.

I agree.  I think there are some cases where the function resolution
code would pick a function declared to take the domain as input, but
it'd be a chancy thing, because for all nontrivial cases the code first
flattens domains to base types.

You can make a separate type that just happens to use the same I/O
functions, and then create a binary-compatible cast to the old type to
allow free use of the existing operators.  This is much more likely to
work reliably.
        regards, tom lane