Closed Mythicaeda closed 5 months ago
and avoids unnecessary errors when message is not a valid json
Should I take this to mean that json
is allowed to be any text, while jsonb
must be valid json?
Should I take this to mean that json is allowed to be any text, while jsonb must be valid json?
No, it's the active cast that's the issue, and this issue would occur regardless of if we were casting to jsonb
or json
.
When you do ->
it comes out as "JSON object field" according to the docs. I'm not sure exactly what Postgres is doing under the hood, but a "JSON object field" is flexible in definition (ie it's allowed to be a string or an int or a nested JSON Object, etc). However, when you actively cast to json
via ::json
, Postgres is looking for either null
or something like '{}'
or '5'
or 'true'
or '"a"'
. Since ''
is none of these, the cast throws an exception rather than converting to the JSON Object version of the string ''
.
Description
Grabbing the
message
field fromerrors
as ajson
rather than astext
that is then converted back tojsonb
is more efficient, more straightforward, and avoids unnecessary errors whenmessage
is not a valid json.Additionally, the type of
errors
in the function has been updated fromjsonb
tojson
to reflect the type that Hasura stores the underlying field as.Verification
Query was tested against the
aerie_dev
database, which contains mission model logs wheremessage
is not a valid json.