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

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)net>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Andres Freund <andres(at)anarazel(dot)de>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Introduce array_shuffle() and array_sample()
Date: 2023-04-03 21:52:31
Message-ID: 4E785594-15B7-48F8-BFBD-485F6D7DBD89@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

> On 3 Apr 2023, at 23:46, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Daniel Gustafsson <daniel(at)yesql(dot)se> writes:
>> On 29 Sep 2022, at 21:33, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> I find this behavior a bit surprising:
>>>
>>> +SELECT array_dims(array_sample('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}'::int[], 3));
>>> + array_dims
>>> +-------------
>>> + [-1:1][2:3]
>>> +(1 row)
>>>
>>> I can buy preserving the lower bound in array_shuffle(), but
>>> array_sample() is not preserving the first-dimension indexes of
>>> the array, so ISTM it ought to reset the first lower bound to 1.
>
>> I might be daft but I'm not sure I follow why not preserving here, can you
>> explain?
>
> Because array_sample selects only some of the (first level) array
> elements, those elements are typically not going to have the same
> indexes in the output as they did in the input. So I don't see why
> it would be useful to preserve the same lower-bound index. It does
> make sense to preserve the lower-order index bounds ([2:3] in this
> example) because we are including or not including those array
> slices as a whole.

Ah, ok, now I see what you mean, thanks! I'll try to fix up the patch like
this tomorrow.

--
Daniel Gustafsson

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message jian he 2023-04-04 01:50:42 Re: ​jsonb @@ jsonpath operator doc: ​Only the first item of the result is taken into account
Previous Message Tom Lane 2023-04-03 21:46:57 Re: [PATCH] Introduce array_shuffle() and array_sample()

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2023-04-03 22:06:02 Re: psql: Add role's membership options to the \du+ command
Previous Message Gregory Stark (as CFM) 2023-04-03 21:47:13 Re: Split index and table statistics into different types of stats