two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
Hello,
Two small ones.
1/ after ALTER TABLE t ALTER CONSTRAINT c, psql offers
nothing so add DEFERRABLE/ENFORCED/INHERIT and their NOT/NO forms.
2/ after ADD [CONSTRAINT c] CHECK (...), psql offers nothing so add NOT
ENFORCED, NOT VALID, NO INHERIT.
Thanks,
Baji Shaik.
Baji Shaik.
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
От:
Baji Shaik <baji.pgdev@gmail.com>
Дата:
Just created a CF entry to track:
On Mon, Oct 5, 2026 at 4:24 PM Baji Shaik <baji.pgdev@gmail.com> wrote:
Hello,Two small ones.1/ after ALTER TABLE t ALTER CONSTRAINT c, psql offersnothing so add DEFERRABLE/ENFORCED/INHERIT and their NOT/NO forms.2/ after ADD [CONSTRAINT c] CHECK (...), psql offers nothing so add NOTENFORCED, NOT VALID, NO INHERIT.Thanks,
Baji Shaik.
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Oct 6, 2026, at 05:24, Baji Shaik wrote:
>
> Hello,
>
> Two small ones.
> 1/ after ALTER TABLE t ALTER CONSTRAINT c, psql offers
> nothing so add DEFERRABLE/ENFORCED/INHERIT and their NOT/NO forms.
>
> 2/ after ADD [CONSTRAINT c] CHECK (...), psql offers nothing so add NOT
> ENFORCED, NOT VALID, NO INHERIT.
>
> Thanks,
> Baji Shaik.
>
> <0001-psql-Add-tab-completion-for-ALTER-TABLE-ALTER-CONSTR.patch><0001-psql-Add-tab-completion-for-CHECK-constraint-modifie.patch>
Thanks for the patch.
I think both 0001 and 0002 share a common problem:
```
evantest=# alter table t alter constraint c not
```
After NOT or NO, tab completion doesn’t suggest any further keywords. Here is an example from the same file for reference:
```
/* ALTER STATISTICS */
else if (Matches("ALTER", "STATISTICS", MatchAny))
COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA", "SET STATISTICS");
/* ALTER STATISTICS SET */
else if (Matches("ALTER", "STATISTICS", MatchAny, "SET"))
COMPLETE_WITH("SCHEMA", "STATISTICS");
```
As you can see, besides suggesting SET SCHEMA and SET STATISTICS, there is a separate rule that matches SET and suggests SCHEMA and STATISTICS. I think we need similar rules for NOT and NO here. And 0001 has the same thing for INITIALLY.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
On Mon, Oct 19, 2026 at 6:33 PM Chao Li <li.evan.chao@gmail.com> wrote:
> On Oct 6, 2026, at 05:24, Baji Shaik <baji.pgdev@gmail.com> wrote:
After NOT or NO, tab completion doesn’t suggest any further keywords. Here is an example from the same file for reference:
```
/* ALTER STATISTICS <name> */
else if (Matches("ALTER", "STATISTICS", MatchAny))
COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA", "SET STATISTICS");
/* ALTER STATISTICS <name> SET */
else if (Matches("ALTER", "STATISTICS", MatchAny, "SET"))
COMPLETE_WITH("SCHEMA", "STATISTICS");
```
As you can see, besides suggesting SET SCHEMA and SET STATISTICS, there is a separate rule that matches SET and suggests SCHEMA and STATISTICS. I think we need similar rules for NOT and NO here. And 0001 has the same thing for INITIALLY.
ah, thank you so much for the review and guidance to fix, Chao. v2 attached.
Let me know if it still misses anything.
Thanks,
Baji Shaik.
Baji Shaik.
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
От:
surya poondla <suryapoondla4@gmail.com>
Дата:
Hi Baji,
I tested v2 on top of fded90eec3e. Both patches apply cleanly (the CHECK one has to go on top of the ALTER CONSTRAINT one) and build
without warnings.
I tested psql through a pty and compared master against patched for about 50 inputs:
- ALTER TABLE t ALTER CONSTRAINT fk <tab> now offers DEFERRABLE,
ENFORCED, INHERIT, INITIALLY DEFERRED/IMMEDIATE, NO INHERIT,
NOT DEFERRABLE, NOT ENFORCED; and NOT/NO/INITIALLY each complete to the matching second word, so Chao's point is addressed.
- ALTER TABLE t ADD [CONSTRAINT c] CHECK (...) <tab> offers NO
INHERIT, NOT ENFORCED, NOT VALID, and NOT/NO follow up correctly.
This also works with nested parentheses in the expression and with CHECK(a>0) written without a space.
- Lower-case input, a schema-qualified table and a quoted constraint name all behave the same.
- The ALTER TABLE rules (ALTER [COLUMN] x ..., ALTER
CONSTRAINT <tab> listing names, DROP/RENAME/VALIDATE CONSTRAINT,
ADD, ADD CONSTRAINT x, ADD [CONSTRAINT x] NOT NULL, PRIMARY
KEY/UNIQUE, ADD c int) give identical output with and without the patches.
I also ran every suggested form against the server, all are accepted. NOT VALID is correctly left out of the ALTER CONSTRAINT list, since
the grammar rejects it there. src/bin/psql/t/010_tab_completion.pl passes.
Two small, optional suggestions:
1. After "ALTER CONSTRAINT fk DEFERRABLE" (or NOT DEFERRABLE)
nothing further is offered, although "DEFERRABLE INITIALLY DEFERRED" is probably the most common way to write it. A rule
offering INITIALLY DEFERRED / INITIALLY IMMEDIATE there would
be nice, but I'm fine leaving it out to keep the patch small.
2. A couple of cases in 010_tab_completion.pl, e.g. for "alter table tab1 alter constraint c not<tab>" and
"... check (a > 0) no<tab>", would keep the new rules from silently regressing.
Neither is a blocker, v2 looks good to me as is.
Regards,
Surya Poondla
I tested v2 on top of fded90eec3e. Both patches apply cleanly (the CHECK one has to go on top of the ALTER CONSTRAINT one) and build
without warnings.
I tested psql through a pty and compared master against patched for about 50 inputs:
- ALTER TABLE t ALTER CONSTRAINT fk <tab> now offers DEFERRABLE,
ENFORCED, INHERIT, INITIALLY DEFERRED/IMMEDIATE, NO INHERIT,
NOT DEFERRABLE, NOT ENFORCED; and NOT/NO/INITIALLY each complete to the matching second word, so Chao's point is addressed.
- ALTER TABLE t ADD [CONSTRAINT c] CHECK (...) <tab> offers NO
INHERIT, NOT ENFORCED, NOT VALID, and NOT/NO follow up correctly.
This also works with nested parentheses in the expression and with CHECK(a>0) written without a space.
- Lower-case input, a schema-qualified table and a quoted constraint name all behave the same.
- The ALTER TABLE rules (ALTER [COLUMN] x ..., ALTER
CONSTRAINT <tab> listing names, DROP/RENAME/VALIDATE CONSTRAINT,
ADD, ADD CONSTRAINT x, ADD [CONSTRAINT x] NOT NULL, PRIMARY
KEY/UNIQUE, ADD c int) give identical output with and without the patches.
I also ran every suggested form against the server, all are accepted. NOT VALID is correctly left out of the ALTER CONSTRAINT list, since
the grammar rejects it there. src/bin/psql/t/010_tab_completion.pl passes.
Two small, optional suggestions:
1. After "ALTER CONSTRAINT fk DEFERRABLE" (or NOT DEFERRABLE)
nothing further is offered, although "DEFERRABLE INITIALLY DEFERRED" is probably the most common way to write it. A rule
offering INITIALLY DEFERRED / INITIALLY IMMEDIATE there would
be nice, but I'm fine leaving it out to keep the patch small.
2. A couple of cases in 010_tab_completion.pl, e.g. for "alter table tab1 alter constraint c not<tab>" and
"... check (a > 0) no<tab>", would keep the new rules from silently regressing.
Neither is a blocker, v2 looks good to me as is.
Regards,
Surya Poondla
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
On Wed, Oct 21, 2026 at 6:30 PM surya poondla <suryapoondla4@gmail.com> wrote:
I also ran every suggested form against the server, all are accepted. NOT VALID is correctly left out of the ALTER CONSTRAINT list, since
the grammar rejects it there. src/bin/psql/t/010_tab_completion.pl passes.
Thank you so much for reviewing and testing.
Two small, optional suggestions:
1. After "ALTER CONSTRAINT fk DEFERRABLE" (or NOT DEFERRABLE)
nothing further is offered, although "DEFERRABLE INITIALLY DEFERRED" is probably the most common way to write it. A rule
offering INITIALLY DEFERRED / INITIALLY IMMEDIATE there would
be nice, but I'm fine leaving it out to keep the patch small.
DEFERRABLE (or NOT DEFERRABLE), tab now offers INITIALLY DEFERRED /
INITIALLY IMMEDIATE, found by looking at ConstraintAttributeElem in
gram.y. One adjustment while doing that: NOT DEFERRABLE only offers
INITIALLY IMMEDIATE, not INITIALLY DEFERRED, I don't think NOT
DEFERRABLE ... INITIALLY DEFERRED is valid (the grammar rejects it:
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"), but
let me know if I'm missing something.
2. A couple of cases in 010_tab_completion.pl, e.g. for "alter table tab1 alter constraint c not<tab>" and
"... check (a > 0) no<tab>", would keep the new rules from silently regressing.
else feels strongly about it, happy to add if so.
v3 of the ALTER CONSTRAINT patch attached, along with the CHECK
constraint patch again (unchanged) for convenience.
Thanks,
Baji Shaik.
Thanks,
Baji Shaik.
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
От:
surya poondla <suryapoondla4@gmail.com>
Дата:
Hi Baji,
I tested v3 together with the CHECK patch on top of b936425002c. Both apply cleanly and build without warnings. Driving psql through a pty
and comparing against master:
- ALTER CONSTRAINT fk DEFERRABLE <tab> offers INITIALLY DEFERRED and INITIALLY IMMEDIATE, and DEFERRABLE INITIALLY <tab> offers DEFERRED
and IMMEDIATE.
- ALTER CONSTRAINT fk NOT DEFERRABLE <tab> completes to INITIALLY IMMEDIATE.
- Everything that worked in v2, including the CHECK modifiers, gives the same output in v3, and the neighbouring ALTER TABLE rules are
identical to master.
The new forms are all accepted by the server, and src/bin/psql/t/010_tab_completion.pl passes.
One correction to my previous mail, v2 of the CHECK patch applies to master on its own as well.
v3 looks good to me.
Regards,
Surya Poondla
I tested v3 together with the CHECK patch on top of b936425002c. Both apply cleanly and build without warnings. Driving psql through a pty
and comparing against master:
- ALTER CONSTRAINT fk DEFERRABLE <tab> offers INITIALLY DEFERRED and INITIALLY IMMEDIATE, and DEFERRABLE INITIALLY <tab> offers DEFERRED
and IMMEDIATE.
- ALTER CONSTRAINT fk NOT DEFERRABLE <tab> completes to INITIALLY IMMEDIATE.
- Everything that worked in v2, including the CHECK modifiers, gives the same output in v3, and the neighbouring ALTER TABLE rules are
identical to master.
The new forms are all accepted by the server, and src/bin/psql/t/010_tab_completion.pl passes.
One correction to my previous mail, v2 of the CHECK patch applies to master on its own as well.
v3 looks good to me.
Regards,
Surya Poondla
Re: two small tab-completion patches (ALTER CONSTRAINT, CHECK modifiers)
От:
Baji Shaik <baji.pgdev@gmail.com>
Дата:
On Tue, Oct 27, 2026 at 5:23 PM surya poondla <suryapoondla4@gmail.com> wrote:
v3 looks good to me.
Thank you so much for the review, Surya.
Marked CF entry as RFC.
Thanks,
Baji Shaik.
Thanks,
Baji Shaik.