Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > "ERROR: operato...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 9489 of 10966
Post > Topic >>

"ERROR: operator is not unique" with Custom Data Type

by david@[EMAIL PROTECTED] ("David E. Wheeler") Jun 5, 2008 at 11:18 AM

Howdy,

I'm working on a custom data type based on TEXT that does case- 
insensitive, locale-aware comparisons, essentially by calling LOWER()  
to compare values. I'll have more to ask about this later, when I want  
to get feedback on the implementation. But right now I'm just writing  
tests and trying to get it all to work the way I think it should.

So I've implemented operators and an operator class for the new type,  
and they work great. I've also added implicit casts between the other  
string data types:

CREATE CAST (lctext AS text)    WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (text AS lctext)    WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (lctext AS varchar) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (varchar AS lctext) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (lctext AS bpchar)  WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST (bpchar AS lctext)  WITHOUT FUNCTION AS IMPLICIT;

However, thanks to the implicit cast PostgreSQL finds more than one  
candidate operator when I compare properly casted values:

try=# select 'a'::lctext =  'a'::text;
ERROR:  operator is not unique: lctext = text
LINE 1: select 'a'::lctext =  'a'::text;
                            ^
HINT:  Could not choose a best candidate operator. You might need to  
add explicit type casts.

So is there a way to resolve this? Would I need to add explicit  
operators between lctext and text (and more, betwein text and lctext),  
assuming that PostgreSQL would find those to be the best candidate  
operators?

I'm kind of hoping that there's a simpler answer, because otherwise  
I'd have to create operators and cl***** for all of:

   ( lctext,  lctext  )
   ( lctext,    text  )
   (   text,  lctext  )
   ( lctext,  lctext  )
   ( lctext,  varchar )
   ( varchar, lctext  )
   ( lctext,  bpchar  )
   ( bpchar,  lctext  )

And then I supposed that I'd have to do the same not only for the  
comparison operators in the operator class, but also any other binary  
operators (concatenation, regular expression, LIKE, etc.). This sounds  
like somewhat of a PITA, though I'd of course just do the cut-and- 
paste work to make it so if that was what's required. But is it? Is  
there no simpler way to do it?

Many thanks,

David

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
 




 7 Posts in Topic:
"ERROR: operator is not unique" with Custom Data Type
david@[EMAIL PROTECTED]   2008-06-05 11:18:26 
Re: "ERROR: operator is not unique" with Custom Data Type
kleptog@[EMAIL PROTECTED]  2008-06-05 20:28:11 
Re: "ERROR: operator is not unique" with Custom Data Type
david@[EMAIL PROTECTED]   2008-06-05 11:37:28 
Re: "ERROR: operator is not unique" with Custom Data Type
tgl@[EMAIL PROTECTED] (T  2008-06-05 14:51:29 
Re: "ERROR: operator is not unique" with Custom Data Type
david@[EMAIL PROTECTED]   2008-06-05 11:54:17 
Re: "ERROR: operator is not unique" with Custom Data Type
kleptog@[EMAIL PROTECTED]  2008-06-05 23:07:32 
Re: "ERROR: operator is not unique" with Custom Data Type
david@[EMAIL PROTECTED]   2008-06-05 17:08:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 11:52:11 CST 2008.