Re: You might be able to move the set-returning function into a LATERAL FROM item.
От | Tom Lane |
---|---|
Тема | Re: You might be able to move the set-returning function into a LATERAL FROM item. |
Дата | |
Msg-id | 11515.1521556077@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | You might be able to move the set-returning function into a LATERALFROM item. (Alexander Farber <alexander.farber@gmail.com>) |
Ответы |
Re: You might be able to move the set-returning function into aLATERAL FROM item.
|
Список | pgsql-general |
Alexander Farber <alexander.farber@gmail.com> writes: > I am trying to fetch a history/protocol of a game with: > SELECT > CASE WHEN JSONB_TYPEOF(tiles) = 'array' THEN > JSONB_ARRAY_ELEMENTS(tiles) ELSE NULL END AS x 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". regards, tom lane
В списке pgsql-general по дате отправления: