Re: Casts from jsonb to other types should cope with json null - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Casts from jsonb to other types should cope with json null
Date
Msg-id 3858623.1722555871@sss.pgh.pa.us
Whole thread Raw
In response to Re: Casts from jsonb to other types should cope with json null  (Maciek Sakrejda <maciek@pganalyze.com>)
Responses Casts from jsonb to other types should cope with json null
List pgsql-hackers
Maciek Sakrejda <maciek@pganalyze.com> writes:
> Oddly, it looks like you only get a null if you use the '->>'
> operator. With '->' and a subsequent cast to text, you get the string
> "null":

> maciek=# select (('{"a":null}'::jsonb)->'a')::text;
>  text
> ------
>  null
> (1 row)

> Is that expected?

I think what is happening there is you're getting the fallback
"cast via I/O" behavior.  There's no jsonb->text cast function
in the catalogs.

Perhaps it's worth adding one, so that it can be made to behave
similarly to the casts to other types.  However, that would be
a compatibility break for a case that doesn't fail today, so
it might be a harder sell than changing cases that do fail.
I'm mildly in favor of doing it, but somebody else might
think differently.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Maciek Sakrejda
Date:
Subject: Re: Casts from jsonb to other types should cope with json null
Next
From: Heikki Linnakangas
Date:
Subject: Re: Refactoring postmaster's code to cleanup after child exit