tab completion of IMPORT FOREIGN SCHEMA
I use IMPORT FOREIGN SCHEMA a bit to set up systems for testing. But not
enough that I can ever remember whether INTO or FROM SERVER comes first in
the syntax.
Here is an improvement to the tab completion, so I don't have to keep
looking it up in the docs.
It accidentally (even before this patch) completes "IMPORT FOREIGN SCHEMA"
with a list of local schemas. This is probably wrong, but I find this
convenient as I often do this in a loop-back setup where the list of
foreign schema would be the same as the local ones. So I don't countermand
that behavior here.
Cheers,
Jeff
Attachments:
foreign_schema_tab_complete.patchapplication/octet-stream; name=foreign_schema_tab_complete.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index eb018854a5..8810968425 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3281,6 +3281,14 @@ 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("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" */
Jeff Janes <jeff.janes@gmail.com> writes:
It accidentally (even before this patch) completes "IMPORT FOREIGN SCHEMA"
with a list of local schemas. This is probably wrong, but I find this
convenient as I often do this in a loop-back setup where the list of
foreign schema would be the same as the local ones. So I don't countermand
that behavior here.
I don't see how psql could obtain a "real" list of foreign schemas
from an arbitrary FDW, even if it magically knew which server the
user would specify later in the command. So this behavior seems fine.
It has some usefulness, while not completing at all would have none.
It might be a good idea to figure out where that completion is
happening and annotate it about this point.
regards, tom lane
On Sun, Aug 09, 2020 at 12:33:43PM -0400, Tom Lane wrote:
I don't see how psql could obtain a "real" list of foreign schemas
from an arbitrary FDW, even if it magically knew which server the
user would specify later in the command. So this behavior seems fine.
It has some usefulness, while not completing at all would have none.
Sounds fine to me as well. The LIMIT TO and EXCEPT clauses are
optional, so using TailMatches() looks fine.
+ else if (TailMatches("FROM", "SERVER", MatchAny, "INTO", MatchAny))
+ COMPLETE_WITH("OPTIONS")
Shouldn't you complete with "OPTIONS (" here?
It would be good to complete with "FROM SERVER" after specifying
EXCEPT or LIMIT TO, you can just use "(*)" to include the list of
tables in the list of elements checked.
--
Michael
On Mon, Aug 17, 2020 at 02:15:34PM +0900, Michael Paquier wrote:
Sounds fine to me as well. The LIMIT TO and EXCEPT clauses are
optional, so using TailMatches() looks fine.+ else if (TailMatches("FROM", "SERVER", MatchAny, "INTO", MatchAny)) + COMPLETE_WITH("OPTIONS") Shouldn't you complete with "OPTIONS (" here?It would be good to complete with "FROM SERVER" after specifying
EXCEPT or LIMIT TO, you can just use "(*)" to include the list of
tables in the list of elements checked.
I have complete the patch with those parts as per the attached. If
there are any objections or extra opinions, please feel free.
--
Michael
Attachments:
foreign_schema_tab_complete_v2.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index f41785f11c..9c6f5ecb6a 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -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" */