From f61bf9da6822bfe85dd02913e95b5a968f582c5a Mon Sep 17 00:00:00 2001 From: Baji Shaik Date: Mon, 19 Oct 2026 19:35:50 -0500 Subject: [PATCH] psql: Add tab completion for CHECK constraint modifiers After ALTER TABLE t ADD [CONSTRAINT c] CHECK (*), psql now suggests NOT ENFORCED, NOT VALID, and NO INHERIT. NOT ENFORCED is a new PG19 feature (commit 342051d73b3) that previously had no tab-completion discoverability. Also add the follow-up completions for NOT and NO, so that choosing one of those words and pressing tab again offers the matching second word, instead of a second dead end. (As pointed out by Chao Li, matching the existing pattern used for e.g. ALTER STATISTICS ... SET.) --- src/bin/psql/tab-complete.in.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index d1061587cc6..17ddffbb185 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -2855,6 +2855,18 @@ match_previous_words(int pattern_id, set_completion_reference(prev7_wd); COMPLETE_WITH_SCHEMA_QUERY(Query_for_unique_index_of_table); } + /* ALTER TABLE xxx ADD [CONSTRAINT yyy] CHECK (...) constraint options */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CHECK", "(*)") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "CHECK", "(*)")) + COMPLETE_WITH("NOT ENFORCED", "NOT VALID", "NO INHERIT"); + /* ALTER TABLE xxx ADD [CONSTRAINT yyy] CHECK (...) NOT */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CHECK", "(*)", "NOT") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "CHECK", "(*)", "NOT")) + COMPLETE_WITH("ENFORCED", "VALID"); + /* ALTER TABLE xxx ADD [CONSTRAINT yyy] CHECK (...) NO */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CHECK", "(*)", "NO") || + Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny, "CHECK", "(*)", "NO")) + COMPLETE_WITH("INHERIT"); /* ALTER TABLE xxx ENABLE */ else if (Matches("ALTER", "TABLE", MatchAny, "ENABLE")) COMPLETE_WITH("ALWAYS", "REPLICA", "ROW LEVEL SECURITY", "RULE", -- 2.54.0 (Apple Git-157)