Re: PostgeSQL JSONB Column with various type of data

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Riswana Rahman <riswana(at)temenos(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>, Manoj Kumar <manojkumar(at)temenos(dot)com>, Dhanya Janardhanan <dhanyaj(at)temenos(dot)com>
Subject: Re: PostgeSQL JSONB Column with various type of data
Date: 2020-12-04 16:31:59
Message-ID: CAHOFxGrm-X0-mL+QyBkO=d3yjgCmSdFhCRCJ3Uf_dkWvfAGvEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, Dec 4, 2020 at 9:21 AM Riswana Rahman <riswana(at)temenos(dot)com> wrote:

> CREATE OR REPLACE FUNCTION jsonbNull(jsonb_column JSONB)
>
> returns boolean as $$
>
> declare
>
> isPoint text := jsonb_typeof(jsonb_column) ;
>
> begin
>
> CASE isPoint
>
> WHEN 'array' THEN
>
> if true = ALL(select
> (jsonb_array_elements(jsonb_column)) = '{}') THEN
>
> return true;
>
> else
>
> return false;
>
> end if;
>
> WHEN 'object' THEN
>
> if jsonb_column = '{}' THEN
>
> return true;
>
> else
>
> return false;
>
> end if;
>
> WHEN 'string' THEN
>
> return false;
>
> ELSE
>
> return true;
>
> END CASE;
>
> end;
>
> $$ LANGUAGE plpgsql IMMUTABLE;
>

As far as I can tell, it seems like this could be re-written as a function
in SQL instead of plpgsql which allows for it to be in-lined. Have you
tested performance and found it to be an issue, or just optimizing in
advance of a need?

>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Nick Cleaton 2020-12-04 22:39:45 Re: Index for range queries on JSON (user defined fields)
Previous Message Marco Colli 2020-12-04 15:39:30 Index for range queries on JSON (user defined fields)