Re: Custom Operators Cannot be Found for Composite Type Values
| От | David E. Wheeler |
|---|---|
| Тема | Re: Custom Operators Cannot be Found for Composite Type Values |
| Дата | |
| Msg-id | 39D50797-720D-4614-81F5-BA6B0677B74C@justatheory.com обсуждение исходный текст |
| Ответ на | Re: Custom Operators Cannot be Found for Composite Type Values (Tom Lane <tgl@sss.pgh.pa.us>) |
| Ответы |
Re: Custom Operators Cannot be Found for Composite Type Values
|
| Список | 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 по дате отправления: