Re: Casts from jsonb to other types should cope with json null

From: Maciek Sakrejda <maciek(at)pganalyze(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Casts from jsonb to other types should cope with json null
Date: 2024-08-01 23:29:58
Message-ID: CADXhmgRQRfzFwK9ctcHoVf1zURESz9KrUEuhkqZPF243ua0kiw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Aug 1, 2024 at 3:52 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-08-01 23:44:31 Re: Casts from jsonb to other types should cope with json null
Previous Message Masahiko Sawada 2024-08-01 23:11:29 Re: Use pgBufferUsage for block reporting in analyze