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

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: "ERROR: operator is not unique" with Custom Data Type
Date: 2008-06-05 18:37:28
Message-ID: 0D46D7ED-3B0A-4B85-9F25-B56684F877AA@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jun 5, 2008, at 11:28, Martijn van Oosterhout wrote:

> On Thu, Jun 05, 2008 at 11:18:26AM -0700, David E. Wheeler wrote:
>> 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.
>
> What makes this different from the citext project?

citext is not locale-aware; please Tom's comments in the "Case-
Insensitve Text Comparison" thread.

>> 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;
>> ^
>
> What would you want postgresql to choose in this case.

I was thinking that the ::text should be cast to ::lctext, as that's
how `'a'::lctext = 'a'` works, but I keep going back and forth in my
mind. Maybe 'a'::lctext should not equal 'A'::text.

> Whichever way
> you want it, make that direction implicit and the other direction
> assignment.

I'm sure I'm missing something simple here. How do I make it assignment?

> Having A->B and B->A both as implicit just leads to
> ambiguity.

Huh. That's what citext has, too:

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

But I agree that there is confusion for PostgreSQL here.

Thanks,

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Lor 2008-06-05 18:43:08 Re: Overhauling GUCS
Previous Message Martijn van Oosterhout 2008-06-05 18:28:11 Re: "ERROR: operator is not unique" with Custom Data Type