Re: Error position support for ComputeIndexAttrs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Kirill Reshke <reshkekirill(at)gmail(dot)com>, Amul Sul <sulamul(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error position support for ComputeIndexAttrs
Date: 2026-01-04 17:28:25
Message-ID: 884405.1767547705@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

jian he <jian(dot)universality(at)gmail(dot)com> writes:
> This will not work for ``ALTER TABLE t ADD CONSTRAINT c UNIQUE (ii);``.
> In this case, gram.y produces a single Constraint node, and Constraint node
> contain only one location field. However, a unique location is required for each
> IndexElem node.

Yeah, the actual problem is that the column name(s) in Constraint are
just a list of String nodes without per-name locations.
transformIndexConstraint throws some errors using constraint->location
that really ought to point at an individual column name, so there's
room for improvement there, as seen in this example from the
regression tests:

-- UNIQUE with a range column/PERIOD that isn't there:
CREATE TABLE temporal_rng3 (
id INTEGER,
CONSTRAINT temporal_rng3_uq UNIQUE (id, valid_at WITHOUT OVERLAPS)
);
ERROR: column "valid_at" named in key does not exist
LINE 3: CONSTRAINT temporal_rng3_uq UNIQUE (id, valid_at WITHOUT O...
^

But this seems like material for a separate patch.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Karlsson 2026-01-04 17:29:36 Re: Optimize JsonbContainerTypeName by reordering type checks
Previous Message Jim Jones 2026-01-04 17:27:25 Re: libxml2 video about its abandonment