+ else if (TailMatches("MERGE", "INTO", MatchAny, "USING") ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAny,
"USING") ||
+ TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny,
"USING"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
+ else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny,
"USING") ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAny,
"USING"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
The latter seems redundant and can be removed. The former seems to
cover all the cases where the latter covers.
+ else if (TailMatches("USING", MatchAny, "ON", MatchAny) ||
+ TailMatches("USING", MatchAny, "ON", MatchAny,
MatchAnyExcept("When"), MatchAnyExcept("When")) ||
+ TailMatches("USING", MatchAny, "AS", MatchAny, "ON",
MatchAny) ||
+ TailMatches("USING", MatchAny, "AS", MatchAny, "ON",
MatchAny,
MatchAnyExcept("When"), MatchAnyExcept("When")) ||
+ TailMatches("USING", MatchAny, MatchAny, "ON",
MatchAny) ||
+ TailMatches("USING", MatchAny, MatchAny, "ON",
MatchAny,
MatchAnyExcept("When"), MatchAnyExcept("When")))
"When" should be "WHEN"?
Regards,
Thanks for reviewing.
Sorry for making such a simple mistake.
I fixed it in v6.
Not only table but also view, foreign table, etc can be specified after
USING in MERGE command. So ISTM that Query_for_list_of_selectables
should be used at the above tab-completion, instead of
Query_for_list_of_tables.
Thought?
That's nice idea!
I took that in v6.
Regards,
Kotaro Kawamoto
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 62a39779b9..70af5acf12 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -4063,23 +4063,25 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_mergetargets);
else if (TailMatches("MERGE", "INTO", MatchAny))
COMPLETE_WITH("USING", "AS");
- else if (TailMatches("MERGE", "INTO", MatchAny, "USING"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
/* with [AS] alias */
- else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny))
- COMPLETE_WITH("USING");
- else if (TailMatches("MERGE", "INTO", MatchAny, MatchAny))
+ else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny) ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAnyExcept("AS")))
COMPLETE_WITH("USING");
- else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
- else if (TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
+ else if (TailMatches("MERGE", "INTO", MatchAny, "USING") ||
+ TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING") ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING"))
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables);
+ else if (TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny) ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny) ||
+ TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny))
+ COMPLETE_WITH("AS", "ON");
/* ON */
- else if (TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny))
- COMPLETE_WITH("ON");
- else if (TailMatches("INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny))
- COMPLETE_WITH("ON");
- else if (TailMatches("INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny))
+ else if (TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny, MatchAnyExcept("ON|AS")) ||
+ TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny, "AS", MatchAny) ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAnyExcept("ON|AS")) ||
+ TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny, "AS", MatchAny) ||
+ TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, MatchAnyExcept("ON|AS")) ||
+ TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny))
COMPLETE_WITH("ON");
/* ON condition */
else if (TailMatches("INTO", MatchAny, "USING", MatchAny, "ON"))
@@ -4089,18 +4091,25 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches("INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny, "ON"))
COMPLETE_WITH_ATTR(prev6_wd);
/* WHEN [NOT] MATCHED */
- else if (TailMatches("USING", MatchAny, "ON", MatchAny))
- COMPLETE_WITH("WHEN MATCHED", "WHEN NOT MATCHED");
- else if (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny))
+ else if (TailMatches("USING", MatchAny, "ON", MatchAny) ||
+ TailMatches("USING", MatchAny, "ON", MatchAny, MatchAnyExcept("WHEN"), MatchAnyExcept("WHEN")) ||
+ TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny) ||
+ TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, MatchAnyExcept("WHEN"), MatchAnyExcept("WHEN")) ||
+ TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny) ||
+ TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, MatchAnyExcept("WHEN"), MatchAnyExcept("WHEN")))
COMPLETE_WITH("WHEN MATCHED", "WHEN NOT MATCHED");
- else if (TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny))
- COMPLETE_WITH("WHEN MATCHED", "WHEN NOT MATCHED");
- else if (TailMatches("WHEN", "MATCHED"))
- COMPLETE_WITH("THEN", "AND");
- else if (TailMatches("WHEN", "NOT", "MATCHED"))
+ else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN") ||
+ TailMatches("USING", MatchAny, "ON", MatchAny, MatchAny, MatchAny, "WHEN") ||
+ TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN") ||
+ TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, MatchAny, MatchAny, "WHEN") ||
+ TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN") ||
+ TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, MatchAny, MatchAny, "WHEN"))
+ COMPLETE_WITH("MATCHED", "NOT MATCHED");
+ else if (TailMatches("WHEN", "MATCHED") ||
+ TailMatches("WHEN", "NOT", "MATCHED"))
COMPLETE_WITH("THEN", "AND");
else if (TailMatches("WHEN", "MATCHED", "THEN"))
- COMPLETE_WITH("UPDATE", "DELETE");
+ COMPLETE_WITH("UPDATE", "DELETE", "DO NOTHING");
else if (TailMatches("WHEN", "NOT", "MATCHED", "THEN"))
COMPLETE_WITH("INSERT", "DO NOTHING");