Re: Does Type Have = Operator? - Mailing list pgsql-hackers

From Fabrízio de Royes Mello
Subject Re: Does Type Have = Operator?
Date
Msg-id CAFcNs+oVXKGfYcXyy6TEU-0Ki8K+G-su54w6YkFdFdU1u+Ej=Q@mail.gmail.com
Whole thread Raw
In response to Re: Does Type Have = Operator?  ("David E. Wheeler" <david@justatheory.com>)
Responses Re: Does Type Have = Operator?  ("David E. Wheeler" <david@justatheory.com>)
List pgsql-hackers


On Wed, May 11, 2016 at 9:09 PM, David E. Wheeler <david@justatheory.com> wrote:
>
> On May 11, 2016, at 11:01 AM, Fabrízio de Royes Mello <fabriziomello@gmail.com> wrote:
>
> > I know... but you can do that just in case the current behaviour fail by cathing it with "begin...exception...", so you'll minimize the looking for process on catalog.
>
> Yeah, I guess. Honestly 90% of this issue would go away for me if there was a `json = json` operator. I know there are a couple different ways to interpret JSON equality, though.
>

Yeah.. it's ugly but you can do something like that:

CREATE OR REPLACE FUNCTION json_equals_to_json(first JSON, second JSON)
RETURNS boolean AS
$$ 
BEGIN
   RETURN first::TEXT IS NOT DISTINCT FROM second::TEXT;
END
$$
LANGUAGE plpgsql IMMUTABLE;

CREATE OPERATOR = (
   LEFTARG = json,
   RIGHTARG = json,
   PROCEDURE = json_equals_to_json
);


Regards,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
>> Timbira: http://www.timbira.com.br
>> Blog: http://fabriziomello.github.io
>> Linkedin: http://br.linkedin.com/in/fabriziomello
>> Twitter: http://twitter.com/fabriziomello
>> Github: http://github.com/fabriziomello

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Use %u to print user mapping's umid and userid
Next
From: "David E. Wheeler"
Date:
Subject: Re: Does Type Have = Operator?