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 equivalence testing. 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 used to 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


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

Reply via email to