Re: Custom Operators Cannot be Found for Composite Type Values - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: Custom Operators Cannot be Found for Composite Type Values
Date
Msg-id 39D50797-720D-4614-81F5-BA6B0677B74C@justatheory.com
Whole thread Raw
In response to Re: Custom Operators Cannot be Found for Composite Type Values  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Custom Operators Cannot be Found for Composite Type Values  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Mar 7, 2012, at 8:23 PM, Tom Lane wrote:

> You have not told the system that your operator is equality for the
> datatype.  It's just a random operator that happens to be named "=".
> We try to avoid depending on operator names as cues to semantics.
> 
> You need to incorporate it into a default hash or btree opclass before
> the composite-type logic will accept it as the thing to use for
> comparing that column.

Ah, okay. Just need more stuff, I guess:
   CREATE OR REPLACE FUNCTION json_cmp(       json,       json   ) RETURNS INTEGER LANGUAGE SQL STRICT IMMUTABLE AS $$
    SELECT bttextcmp($1::text, $2::text);   $$;
 
   CREATE OR REPLACE FUNCTION json_eq(       json,       json   ) RETURNS BOOLEAN LANGUAGE SQL STRICT IMMUTABLE AS $$
   SELECT bttextcmp($1::text, $2::text) = 0;   $$;
 
   CREATE OPERATOR = (       LEFTARG   = json,       RIGHTARG  = json,       PROCEDURE = json_eq   );
   CREATE OPERATOR CLASS json_ops   DEFAULT FOR TYPE JSON USING btree AS   OPERATOR    3   =  (json, json),   FUNCTION
 1   json_cmp(json, json);
 

This seems to work.

Best,

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: A minor rant: pay attention to updating the comments!
Next
From: Tom Lane
Date:
Subject: Re: Custom Operators Cannot be Found for Composite Type Values