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

From David E. Wheeler
Subject Custom Operators Cannot be Found for Composite Type Values
Date
Msg-id C92C9BFA-AB22-42FF-B74C-D7760A92AE62@justatheory.com
Whole thread Raw
Responses Re: Custom Operators Cannot be Found for Composite Type Values
List pgsql-hackers
Hackers,

I’m doing some development with the new JSON type (actually, Andrew’s backport to 9.1) and needed to do some very basic
equivalencetesting. So I created a custom operator: 
   CREATE OR REPLACE FUNCTION json_eq(       json,       json   ) RETURNS BOOLEAN LANGUAGE SQL STRICT IMMUTABLE AS $$
   SELECT $1::text = $2::text;   $$; 
   CREATE OPERATOR = (       LEFTARG   = json,       RIGHTARG  = json,       PROCEDURE = json_eq   );

With this in place, these work:
    SELECT '{}'::json = '{}'::json;    SELECT ROW('{}'::json) = ROW('{}'::json);

However this does not:
   create type ajson AS (a json);   SELECT ROW('{}'::json)::ajson = ROW('{}'::json)::ajson;

That last line emits an error:
   ERROR:  could not identify an equality operator for type json

To which my response was: WTF? Is this expected behavior? Is there something about custom operators that they can’t be
usedto compare the values of values in composite types? 

I’ve worked around it by writing a separate operator to compare ajson types using
   SELECT $1::text = $2::text

But it’s a bit annoying.

Thanks,

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Collect frequency statistics for arrays
Next
From: Thom Brown
Date:
Subject: pg_basebackup streaming issue from standby