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

From Maciek Sakrejda
Subject Re: Casts from jsonb to other types should cope with json null
Date
Msg-id CADXhmgRQRfzFwK9ctcHoVf1zURESz9KrUEuhkqZPF243ua0kiw@mail.gmail.com
Whole thread Raw
In response to Casts from jsonb to other types should cope with json null  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Casts from jsonb to other types should cope with json null
List pgsql-hackers
On Thu, Aug 1, 2024 at 3:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I complained in the discussion of bug #18564 [1] that it's quite
> inconsistent that you can cast a jsonb null to text and get
> a SQL NULL:
>
> =# select ('{"a": null}'::jsonb)->>'a';
>  ?column?
> ----------
>
> (1 row)

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?



pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Use pgBufferUsage for block reporting in analyze
Next
From: Tom Lane
Date:
Subject: Re: Casts from jsonb to other types should cope with json null