From 9a941a33bab6ed8a5a0b818f45844f1014627383 Mon Sep 17 00:00:00 2001 From: Sho Ito Date: Mon, 23 Nov 2026 00:03:17 -0500 Subject: [PATCH v5 1/2] psql: Fix REPACK tab completion around USING INDEX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complete INDEX after an explicitly typed USING, including with command options or a column list. When completing an index name after a column list, skip the column list to find the target table instead of falling back to indexes from unrelated tables. Offer USING INDEX after a column list and offer an opening parenthesis after a table name when an option list is present. These suggestions do not inspect the ANALYZE setting; the server validates whether the column list is allowed. Author: Sho Ito Reviewed-by: Chao Li Reviewed-by: Ishjaap Singh Suggested-by: Álvaro Herrera Backpatch-through: 19 Discussion: https://postgr.es/m/CAG7L5+7Xmus+JLa0m=Lpw49wU=secPm5dzNd2ibmfvhdSYEfqA@mail.gmail.com --- src/bin/psql/tab-complete.in.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 96de78cd08..a1c1aa5655 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -5129,24 +5129,26 @@ match_previous_words(int pattern_id, else if (Matches("REPACK", "(*)")) COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_clusterables, "USING INDEX"); - else if (Matches("REPACK", MatchAnyExcept("("))) + else if (Matches("REPACK", "USING") || + Matches("REPACK", "(*)", "USING") || + Matches("REPACK", MatchAny, "USING") || + Matches("REPACK", "(*)", MatchAny, "USING") || + Matches("REPACK", "(*)", MatchAny, "(*)", "USING")) + COMPLETE_WITH("INDEX"); + else if (Matches("REPACK", MatchAnyExcept("(")) || + Matches("REPACK", "(*)", MatchAny, "(*)")) COMPLETE_WITH("USING INDEX"); else if (Matches("REPACK", "(*)", MatchAnyExcept("("))) - COMPLETE_WITH("USING INDEX"); + COMPLETE_WITH("(", "USING INDEX"); else if (Matches("REPACK", MatchAny, "USING", "INDEX") || Matches("REPACK", "(*)", MatchAny, "USING", "INDEX")) { set_completion_reference(prev3_wd); COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table); } - - /* - * Complete ... [ (*) ] USING INDEX, with a list of indexes for - * . - */ - else if (TailMatches(MatchAny, "USING", "INDEX")) + else if (Matches("REPACK", "(*)", MatchAny, "(*)", "USING", "INDEX")) { - set_completion_reference(prev3_wd); + set_completion_reference(prev4_wd); COMPLETE_WITH_SCHEMA_QUERY(Query_for_index_of_table); } else if (HeadMatches("REPACK", "(*") && -- 2.48.1