Re: You might be able to move the set-returning function into a LATERAL FROM item.

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: You might be able to move the set-returning function into a LATERAL FROM item.
Date: 2018-03-20 19:23:54
Message-ID: CAADeyWjkUPBXoQ0GQBO60XK0sMrN=63aobK_4ktTJhVk6syQEA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you -

On Tue, Mar 20, 2018 at 3:27 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> I think you could push the conditionality into a plpgsql function,
> something like (untested)
>
> create function jsonb_elements_if_array(j jsonb) returns setof jsonb as $$
> begin
> if jsonb_typeof(j) = 'array' then
> return query select jsonb_array_elements(j);
> end if;
> end$$
> strict immutable language plpgsql;
>
> Note that this gives *no* elements, rather than a single NULL value,
> if the input isn't an array --- but that seems to me to make more sense
> than your existing code anyhow. If you disagree, add "else return next
> null::jsonb".
>

I think I will just introduce a separate column (until now I was trying to
squeeze 2 different kinds of data - JSON array of objects and a string -
into the one column)... I believe Adrian had suggested it before :-)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-03-20 19:24:17 Re: FATAL: semctl(15073290, 4, SETVAL, 0) failed: Invalid argument
Previous Message Adrian Klaver 2018-03-20 19:21:37 Re: FDW Foreign Table Access: strange LOG message