From 2a35d486b8263744f10af6702408764befc03e87 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Fri, 1 Nov 2024 10:39:27 +0000 Subject: [PATCH v1] Add missing psql tab completion for som ALTER TABLE patterns ALTER TABBLE patterns that are not tab-completed via psql: ALTER TABLE ADD IF NOT EXISTS ALTER TABLE ADD COLUMN IF NOT EXISTS */ --- src/bin/psql/tab-complete.in.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 1be0056af7..4b5334f2f0 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -2689,12 +2689,20 @@ match_previous_words(int pattern_id, /* ALTER TABLE xxx ADD */ else if (Matches("ALTER", "TABLE", MatchAny, "ADD")) { - /* make sure to keep this list and the !Matches() below in sync */ + /* make sure to keep this list and the !Matches() below in sync, except for + * IF NOT EXISTS, becuse "IF" is valid column name */ COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY", - "EXCLUDE", "FOREIGN KEY"); + "EXCLUDE", "FOREIGN KEY", "IF NOT EXISTS"); } - /* ALTER TABLE xxx ADD [COLUMN] yyy */ - else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) || + /* ALTER TABLE xxx ADD IF NOT EXISTS */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN")) + { + COMPLETE_WITH("IF NOT EXISTS"); + } + /* ALTER TABLE xxx ADD [IF NOT EXISTS] [COLUMN] yyy */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "IF", "NOT", "EXISTS", MatchAny) || + Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", "IF", "NOT", "EXISTS", MatchAny) || + Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) || Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAnyExcept("COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN"))) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes); /* ALTER TABLE xxx ADD CONSTRAINT yyy */ -- 2.34.1