From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, Erik Rijkers <er(at)xs4all(dot)nl> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: ERROR: operator does not exist: json = json |
Date: | 2022-07-08 15:00:09 |
Message-ID: | 2f992dc4-3427-0d1c-1b66-d6b78c0060ce@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2022-07-08 Fr 07:57, Dagfinn Ilmari Mannsåker wrote:
> Erik Rijkers <er(at)xs4all(dot)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.
Alternatively, if you really need something like this, try
<https://bitbucket.org/adunstan/jsoncmp/src/master/>
(I should probably update it to mark the functions as parallel safe)
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2022-07-08 15:04:20 | Re: [PATCH] fix wait_event of pg_stat_activity in case of high amount of connections |
Previous Message | Robert Haas | 2022-07-08 14:44:07 | Re: pg15b2: large objects lost on upgrade |