Re: ScalarArrayOpExpr and multi-dimensional arrays

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ScalarArrayOpExpr and multi-dimensional arrays
Date: 2017-12-11 02:30:02
Message-ID: 0fd1b9d4-057c-a806-861d-62c7b83a94d3@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2017/12/08 23:34, Tom Lane wrote:
> Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> writes:
>> I wonder if ScalarArrayOpExpr is not really meant for multi-dimensional
>> arrays appearing on the right hand side? Because:
>> # select array[1] = any (array[array[1], array[2]]);
>
>> ERROR: operator does not exist: integer[] = integer
>
> You are falling into the misimpression that a 2-D array is an array of
> 1-D arrays. It is not, even if the syntax makes it look like that.
>
> ScalarArrayOpExpr just iterates over the array elements without regard
> to dimensionality; so the LHS must be of the element type.

Yeah, I can now see that.

Although, I wonder if there is any room for improvement here. Instead of
waiting for make_scalar_array_op() to emit the error as it does today,
would it be better if we error'd out earlier saying "ERROR: ANY/ALL
leftarg must be scalar, not array"? Attached a patch for that, if it's
worth going for at all.

Thanks,
Amit

Attachment Content-Type Size
scalar-array-op-lhs-scalar.patch text/plain 2.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2017-12-11 02:51:19 Parallel Index Scan vs BTP_DELETED and BTP_HALF_DEAD
Previous Message David Rowley 2017-12-10 21:32:19 Re: Out of date comment in cached_plan_cost