Re: Extract numeric filed in JSONB more effectively

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Extract numeric filed in JSONB more effectively
Date: 2023-08-01 23:33:37
Message-ID: CAKU4AWpoX9aNosepmz_y9gJhkWo0O=0HEtpThxJQiS16LHWWBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Aug 1, 2023 at 7:03 PM Matthias van de Meent <
boekewurm+postgres(at)gmail(dot)com> wrote:

> On Tue, 1 Aug 2023 at 06:39, Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> wrote:
> >
> > Hi:
> >
> > Currently if we want to extract a numeric field in jsonb, we need to use
> > the following expression: cast (a->>'a' as numeric). It will turn a
> numeric
> > to text first and then turn the text to numeric again.
>
> Why wouldn't you use cast(a->'a' as numeric), or ((a->'a')::numeric)?
>

Thanks for this information! I didn't realize we have this function
already at [1].

https://www.postgresql.org/docs/15/functions-json.html

--
Best Regards
Andy Fan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2023-08-01 23:38:40 Re: Support to define custom wait events for extensions
Previous Message Tom Lane 2023-08-01 22:28:52 Re: stats test intermittent failure