From: | "David E(dot) Wheeler" <david(at)justatheory(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Custom Operators Cannot be Found for Composite Type Values |
Date: | 2012-03-08 19:00:24 |
Message-ID: | 39D50797-720D-4614-81F5-BA6B0677B74C@justatheory.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2012-03-08 19:16:33 | Re: Custom Operators Cannot be Found for Composite Type Values |
Previous Message | Tom Lane | 2012-03-08 18:44:28 | A minor rant: pay attention to updating the comments! |