Re: Cleaning up array_in()

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: jian he <jian.universality@gmail.com>, Alexander Lakhin <exclusion@gmail.com>, Nikhil Benesch <nikhil.benesch@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2023-11-13T18:23:30Z
Lists: pgsql-hackers

Attachments

I wrote:
> Heikki Linnakangas <hlinnaka@iki.fi> writes:
>> 2. This was the same before this patch, but:

>> postgres=# select '{{{{{{{{{{1}}}}}}}}}}'::int[];
>> ERROR:  number of array dimensions (7) exceeds the maximum allowed (6)
>> LINE 1: select '{{{{{{{{{{1}}}}}}}}}}'::int[];
>> ^
>> The error message isn't great, as the literal contains 10 dimensions, 
>> not 7 as the error message claims.

> Yeah.  To make that report accurate, we'd have to somehow postpone
> issuing the error until we've seen all the left braces (or at least
> all the initial ones).  There's a related problem in reading an
> explicitly-dimensioned array:

> postgres=# select '[1][2][3][4][5][6][7][8][9]={}'::text[];
> ERROR:  number of array dimensions (7) exceeds the maximum allowed (6)

> I kind of think it's not worth the trouble.  What was discussed
> upthread was revising the message to not claim it knows how many
> dimensions there are.

I pushed the main patch.  Here's a proposed delta to deal with
the bogus-dimensionality-count issue.  There are a few more places
where I left things alone because the code does know what the
intended dimensionality will be; so there are still two versions
of the translatable error message.

			regards, tom lane

Commits

  1. Don't specify number of dimensions in cases where we don't know it.

  2. Improve readability and error detection of array_in().

  3. Add trailing commas to enum definitions