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

Поиск
Список
Период
Сортировка
От Alexander Farber
Тема Re: You might be able to move the set-returning function into aLATERAL FROM item.
Дата
Msg-id CAADeyWjkUPBXoQ0GQBO60XK0sMrN=63aobK_4ktTJhVk6syQEA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: You might be able to move the set-returning function into a LATERAL FROM item.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Thank you -

On Tue, Mar 20, 2018 at 3:27 PM, Tom Lane <tgl@sss.pgh.pa.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 :-)

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: FDW Foreign Table Access: strange LOG message
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: FATAL: semctl(15073290, 4, SETVAL, 0) failed: Invalid argument