Improve tab completion of IMPORT FOREIGN SCHEMA in psql
authorMichael Paquier <[email protected]>
Thu, 17 Sep 2020 02:49:29 +0000 (11:49 +0900)
committerMichael Paquier <[email protected]>
Thu, 17 Sep 2020 02:49:29 +0000 (11:49 +0900)
It is not possible to get a list of foreign schemas as the server is not
known, so this provides instead a list of local schemas, which is more
useful than nothing if using a loopback server or having schema names
matching in the local and remote servers.

Author: Jeff Janes
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/CAMkU=1wr7Roj41q-XiJs=Uyc2xCmHhcGGy7J-peJQK-e+w=ghw@mail.gmail.com

src/bin/psql/tab-complete.c

index f41785f11c12e68d4f63facd1699e1ccf898e586..9c6f5ecb6a8c78d2a8ceaa82b6efa79dceafe9c0 100644 (file)
@@ -3293,6 +3293,17 @@ psql_completion(const char *text, int start, int end)
        COMPLETE_WITH("FOREIGN SCHEMA");
    else if (Matches("IMPORT", "FOREIGN"))
        COMPLETE_WITH("SCHEMA");
+   else if (Matches("IMPORT", "FOREIGN", "SCHEMA", MatchAny))
+       COMPLETE_WITH("EXCEPT (", "FROM SERVER", "LIMIT TO (");
+   else if (TailMatches("LIMIT", "TO", "(*)") ||
+            TailMatches("EXCEPT", "(*)"))
+       COMPLETE_WITH("FROM SERVER");
+   else if (TailMatches("FROM", "SERVER", MatchAny))
+       COMPLETE_WITH("INTO");
+   else if (TailMatches("FROM", "SERVER", MatchAny, "INTO"))
+       COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+   else if (TailMatches("FROM", "SERVER", MatchAny, "INTO", MatchAny))
+       COMPLETE_WITH("OPTIONS (");
 
 /* INSERT --- can be inside EXPLAIN, RULE, etc */
    /* Complete INSERT with "INTO" */