Re: [PATCH] Introduce array_shuffle() and array_sample()

Поиск
Список
Период
Сортировка
От Martin Kalcher
Тема Re: [PATCH] Introduce array_shuffle() and array_sample()
Дата
Msg-id 091a9f69-1e5d-6558-41a7-2607a5fc9ff7@aboutsource.net
обсуждение исходный текст
Ответ на Re: [PATCH] Introduce array_shuffle() and array_sample()  (Martin Kalcher <martin.kalcher@aboutsource.net>)
Ответы Re: [PATCH] Introduce array_shuffle() and array_sample()  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
Am 18.07.22 um 23:48 schrieb Martin Kalcher:
> 
> If we go with (1) array_shuffle() and array_sample() should shuffle each 
> element individually and always return a one-dimensional array.
> 
>    select array_shuffle('{{1,2},{3,4},{5,6}}');
>    -----------
>     {1,4,3,5,6,2}
> 
>    select array_sample('{{1,2},{3,4},{5,6}}', 3);
>    ----------
>     {1,4,3}
> 
> If we go with (2) both functions should only operate on the first 
> dimension and shuffle whole subarrays and keep the dimensions intact.
> 
>    select array_shuffle('{{1,2},{3,4},{5,6}}');
>    ---------------------
>     {{3,4},{1,2},{5,6}}
> 
>    select array_sample('{{1,2},{3,4},{5,6}}', 2);
>    ---------------
>     {{3,4},{1,2}}
> 

Having thought about it, i would go with (2). It gives the user the 
ability to decide wether or not array-of-arrays behavior is desired. If 
he wants the behavior of (1) he can flatten the array before applying 
array_shuffle(). Unfortunately there is no array_flatten() function (at 
the moment) and the user would have to work around it with unnest() and 
array_agg().



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

Предыдущее
От: Japin Li
Дата:
Сообщение: Re: Memory leak fix in psql
Следующее
От: Antonin Houska
Дата:
Сообщение: Re: Proposal: allow database-specific role memberships