From: | "David E(dot) Wheeler" <david(at)justatheory(dot)com> |
---|---|
To: | pgsql-hackers Hackers <pgsql-hackers(at)postgreSQL(dot)org> |
Subject: | Custom Operators Cannot be Found for Composite Type Values |
Date: | 2012-03-08 01:17:08 |
Message-ID: | C92C9BFA-AB22-42FF-B74C-D7760A92AE62@justatheory.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 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
From | Date | Subject | |
---|---|---|---|
Next Message | Ali Ahmed | 2012-03-08 01:25:18 | Requesting Ideas fro project proposal. |
Previous Message | Tom Lane | 2012-03-08 00:51:42 | Re: Collect frequency statistics for arrays |