Re: TRIM_ARRAY

Поиск
Список
Период
Сортировка
От Isaac Morland
Тема Re: TRIM_ARRAY
Дата
Msg-id CAMsGm5eseX1Sc1u=d5Prv_44CiMuhvtLnYFa2mFeic0oktqDWQ@mail.gmail.com
обсуждение исходный текст
Ответ на TRIM_ARRAY  (Vik Fearing <vik@postgresfriends.org>)
Ответы Re: TRIM_ARRAY  (Vik Fearing <vik@postgresfriends.org>)
Список pgsql-hackers
On Tue, 16 Feb 2021 at 12:54, Vik Fearing <vik@postgresfriends.org> wrote:
The SQL standard defines a function called TRIM_ARRAY that surprisingly
has syntax that looks like a function!  So I implemented it using a thin
wrapper around our array slice syntax.  It is literally just ($1)[1:$2].

An interesting case that I decided to handle by explaining it in the
docs is that this won't give you the first n elements if your lower
bound is not 1.  My justification for this is 1) non-standard lower
bounds are so rare in the wild that 2) people using them can just not
use this function.  The alternative is to go through the unnest dance
(or write it in C) which defeats inlining.

I don't recall ever seeing non-default lower bounds, so I actually think it's OK to just rule out that scenario, but why not something like this:

($1)[:array_lower ($1, 1) + $2 - 1]

Note that I've used the 9.6 feature that allows omitting the lower bound.

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

Предыдущее
От: Vik Fearing
Дата:
Сообщение: TRIM_ARRAY
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: PoC/WIP: Extended statistics on expressions