Custom Operators Cannot be Found for Composite Type Values
От | David E. Wheeler |
---|---|
Тема | Custom Operators Cannot be Found for Composite Type Values |
Дата | |
Msg-id | C92C9BFA-AB22-42FF-B74C-D7760A92AE62@justatheory.com обсуждение исходный текст |
Ответы |
Re: Custom Operators Cannot be Found for Composite Type Values
|
Список | 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 по дате отправления: