public inbox for [email protected]
help / color / mirror / Atom feedFrom: Alvaro Herrera <[email protected]>
To: jian he <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: alter table add x wrong error position
Date: Fri, 12 Jan 2024 10:58:21 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CACJufxHU9ZdA=-Q+fg_+v+6OJ-L05rez8_mNZBrKghYD_g04XA@mail.gmail.com>
On 2024-Jan-08, jian he wrote:
> hi.
> Maybe this is a small printout err_position bug.
>
> create table atacc2 ( test int, a int, b int) ;
> success tests:
> alter table atacc2 add CONSTRAINT x PRIMARY KEY (id, b );
> alter table atacc2 add CONSTRAINT x PRIMARY KEY (id, b a);
> alter table atacc2 add CONSTRAINT x PRIMARY KEYa (id, b);
>
> tests have problem:
> alter table atacc2 add constraints x unique (test, a, b);
> ERROR: syntax error at or near "("
> LINE 1: alter table atacc2 add constraints x unique (test, a, b);
>
> ^
> ADD either following with the optional keyword "COLUMN" or
> "CONSTRAINT" as the doc.
> so I should expect the '^' point at "constraints"?
Here you're saying to add a column called constraints, of
type x; then UNIQUE is parsed by columnDef as ColQualList, which goes to
the ColConstraintElem production starting with the UNIQUE keyword:
| UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
so the next thing could be opt_unique_null_treatment or opt_definition
or OptConsTableSpace or going back to ColQualList, but none of those
start with a '(' parens. So the ( doesn't have a match and you get the
syntax error.
If you don't misspell CONSTRAINT as "constraints", there's no issue.
I don't see any way to improve this. You can't forbid misspellings of
the keyword CONSTRAINT, because they can be column names.
alter table atacc2 add cnstrnt x unique (test, a, b);
ERROR: error de sintaxis en o cerca de «(»
LÍNEA 1: alter table atacc2 add cnstrnt x unique (test, a, b);
^
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
view thread (4+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: alter table add x wrong error position
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox