From f2bbadce6b5052337a11a33ea6bd8d8aebe2610a Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 31 Aug 2021 12:07:20 +0900 Subject: [PATCH] Add tab completion for data types after ALTER TABLE ADD [COLUMN] in psql MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows finding data types that can be used for the creation of a new column, completing d3fa876. Author: Dagfinn Ilmari Mannsåker Discussion: https://postgr.es/m/87h7f7uk6s.fsf@wibble.ilmari.org --- src/bin/psql/tab-complete.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 7c6af435a95..76462412db5 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2025,8 +2025,16 @@ psql_completion(const char *text, int start, int end) "DETACH PARTITION", "FORCE ROW LEVEL SECURITY"); /* ALTER TABLE xxx ADD */ else if (Matches("ALTER", "TABLE", MatchAny, "ADD")) + { + /* make sure to keep this list and the !Matches() below in sync */ COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY"); + } + /* ATER TABLE xxx ADD [COLUMN] yyy */ + else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) || + (Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAny) && + !Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN"))) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL); /* ALTER TABLE xxx ADD CONSTRAINT yyy */ else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny)) COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY");