Re: ERROR: operator does not exist: json = json - Mailing list pgsql-hackers

From Dagfinn Ilmari Mannsåker
Subject Re: ERROR: operator does not exist: json = json
Date
Msg-id 87wncnizq8.fsf@wibble.ilmari.org
Whole thread Raw
In response to ERROR: operator does not exist: json = json  (Erik Rijkers <er@xs4all.nl>)
Responses Re: ERROR: operator does not exist: json = json
List pgsql-hackers
Erik Rijkers <er@xs4all.nl> writes:

> Hi,
>
> Comparison of 2 values of type jsonb is allowed.
>
> Comparison of 2 values of type json gives an error.
>
> That seems like an oversight -- or is it deliberate?

This is because json is just a textual representation, and different
JSON strings can be semantically equal because e.g. whitespace and
object key order is not significant.

> Example:
>
> select '42'::json = '{}'::json;
> --> ERROR:  operator does not exist: json = json
>
> (of course, easily 'solved' by casting but that's not really the
> point)

To do a proper comparison you have to parse it into a semantic form,
which is what casting to jsonb does.

> Thanks,
>
> Erik Rijkers

- ilmari



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Add function to return backup_label and tablespace_map
Next
From: David Steele
Date:
Subject: Re: Add function to return backup_label and tablespace_map