Re: Cleaning up array_in()

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Nikhil Benesch <nikhil(dot)benesch(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Cleaning up array_in()
Date: 2023-11-12 23:30:52
Message-ID: 971eebc7-44aa-498d-8f9f-a3c0b3ab7cba@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 09/11/2023 18:57, Tom Lane wrote:
> After further thought I concluded that this area is worth spending
> a little more code for. If we have input like '{foo"bar"}' or
> '{"foo"bar}' or '{"foo""bar"}', what it most likely means is that
> the user misunderstood the quoting rules. A message like "Unexpected
> array element" is pretty completely unhelpful for figuring that out.
> The alternative I was considering, "Unexpected """ character", would
> not be much better. What we want to say is something like "Incorrectly
> quoted array element", and the attached v12 makes ReadArrayToken do
> that for both quoted and unquoted cases.

+1

> I also fixed the obsolete documentation that Alexander noted, and
> cleaned up a couple other infelicities (notably, I'd blindly written
> ereport(ERROR) in one place where ereturn is now the way).
>
> Barring objections, I think v12 is committable.

Looks good to me. Just two little things caught my eye:

1.

> /* Initialize dim, lBound for ReadArrayDimensions, ReadArrayStr */
> for (int i = 0; i < MAXDIM; i++)
> {
> dim[i] = -1; /* indicates "not yet known" */
> lBound[i] = 1; /* default lower bound */
> }

The function comments in ReadArrayDimensions and ReadArrayStr don't make
it clear that these arrays need to be initialized like this.
ReadArrayDimensions() says that they are output variables, and
ReadArrayStr() doesn't mention anything about having to initialize them.

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.

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-11-12 23:31:50 Re: pg_walfile_name_offset can return inconsistent values
Previous Message Thomas Munro 2023-11-12 23:08:57 Re: ResourceOwner refactoring