Re: [PATCH]Feature improvement for MERGE tab completion
> On 28 Mar 2023, at 20:55, Gregory Stark (as CFM) wrote: > > It looks like this remaining work isn't going to happen this CF and > therefore this release. There hasn't been an update since January when > Dean Rasheed posted a review. > > Unless there's any updates soon I'll move this on to the next > commitfest or mark it returned with feedback. There are still no updates to this patch or thread, so I'm closing this as Returned with Feedback. Please feel free to resubmit to a future CF when there is renewed interest in working on this. -- Daniel Gustafsson
Re: [PATCH]Feature improvement for MERGE tab completion
Ah, another thread with a bouncing email address... Please respond to to thread from this point to avoid bounces. -- Gregory Stark As Commitfest Manager
Re: [PATCH]Feature improvement for MERGE tab completion
It looks like this remaining work isn't going to happen this CF and therefore this release. There hasn't been an update since January when Dean Rasheed posted a review. Unless there's any updates soon I'll move this on to the next commitfest or mark it returned with feedback. -- Gregory Stark As Commitfest Manager
Re: [PATCH]Feature improvement for MERGE tab completion
On Tue, 3 Jan 2023 at 12:30, vignesh C wrote: > > The patch does not apply on top of HEAD as in [1], please post a rebased > patch: > This is because 0001 has been committed. Re-uploading 0002, to keep the CF-bot happy. Reviewing 0002... I'm not entirely convinced that the PartialMatches() changes are really necessary. As far as I can see USING followed by ON doesn't appear anywhere else in the grammar, and the later completions involving WHEN [NOT] MATCHED are definitely unique to MERGE. Nonetheless, I guess it's not a bad thing to check that it really is a MERGE. Also the new matching function might prove useful for other cases. Some more detailed code comments: I find the name PartialMatches() a little off, since "partial" doesn't really accurately describe what it's doing. HeadMatches() and TailMatches() are also partial matches (matching the head and tail parts). So perhaps MidMatches() would be a better name. I also found the comment description of PartialMatchesImpl() misleading: /* * Implementation of PartialMatches and PartialMatchesCS macros: do parts of * the words in previous_words match the variadic arguments? */ I think a more accurate description would be: /* * Implementation of MidMatches and MidMatchesCS macros: do any N consecutive * words in previous_words match the variadic arguments? */ Similarly, instead of: /* Match N words on the line partially, case-insensitively. */ how about: /* Match N consecutive words anywhere on the line, case-insensitively. */ In PartialMatchesImpl()'s main loop: if (previous_words_count - startpos < narg) { va_end(args); return false; } couldn't that just be built into the loop's termination clause (i.e., loop while startpos <= previous_words_count - narg)? For the first block of changes using the new function: else if (PartialMatches("MERGE", "INTO", MatchAny, "USING") || PartialMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING") || PartialMatches("MERGE", "INTO", MatchAny, MatchAny, "USING")) { /* Complete MERGE INTO ... ON with target table attributes */ if (TailMatches("INTO", MatchAny, "USING", MatchAny, "ON")) COMPLETE_WITH_ATTR(prev4_wd); else if (TailMatches("INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny, "ON")) COMPLETE_WITH_ATTR(prev8_wd); else if (TailMatches("INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny, "ON")) COMPLETE_WITH_ATTR(prev6_wd); wouldn't it be simpler to just include "MERGE" in the TailMatches() arguments, and leave these 3 cases outside the new code block. I.e.: /* Complete MERGE INTO ... ON with target table attributes */ else if (TailMatches("MERGE", "INTO", MatchAny, "USING", MatchAny, "ON")) COMPLETE_WITH_ATTR(prev4_wd); else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny, "ON")) COMPLETE_WITH_ATTR(prev8_wd); else if (TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny, "ON")) COMPLETE_WITH_ATTR(prev6_wd); Regards, Dean From 8c7e25e4a2d939a32751bd9a0d487c510ec66191 Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Wed, 21 Sep 2022 13:58:50 +0900 Subject: [PATCH 2/2] psql: Add PartialMatches() macro for better tab-completion. --- src/bin/psql/tab-complete.c | 152 +++- 1 file changed, 113 insertions(+), 39 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 820f47d23a..0b8c252615 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1582,6 +1582,65 @@ HeadMatchesImpl(bool case_sensitive, return true; } +/* + * Implementation of PartialMatches and PartialMatchesCS macros: do parts of + * the words in previous_words match the variadic arguments? + */ +static bool +PartialMatchesImpl(bool case_sensitive, + int previous_words_count, char **previous_words, + int narg,...) +{ + va_list args; + char *firstarg = NULL; + + if (previous_words_count < narg) + return false; + + for (int startpos = 0; startpos < previous_words_count; startpos++) + { + int argno; + + if (firstarg == NULL) + { + va_start(args, narg); + firstarg = va_arg(args, char *); + } + + if (!word_matches(firstarg, + previous_words[previous_words_count - startpos - 1], + case_sensitive)) + continue; + + if (previous_words_count - startpos < narg) + { + va_end(args); + return false; + } + + for (argno = 1; argno < narg; argno++) + { + const char *arg = va_arg(args, const char *); + + if (!word_matches(arg, + previous_words[previous_words_count - argno - startpos - 1], + case_sensitive)) +break; + } + + va_end(args); + firstarg = NULL; + + if (argno == narg) + return true; + } + + if (firstarg != NULL) + va_end(args); + + return false; +} + /* * Check if
Re: [PATCH]Feature improvement for MERGE tab completion
On Wed, 21 Sept 2022 at 10:55, Fujii Masao wrote: > > > > On 2022/09/21 0:51, Alvaro Herrera wrote: > > The rules starting at line 4111 make me a bit nervous, since nowhere > > we're restricting them to operating only on MERGE lines. I don't think > > it's a real problem since USING is not terribly common anyway. Likewise > > for the ones with WHEN [NOT] MATCHED. I kinda wish we had a way to > > search for stuff like "keyword MERGE appears earlier in the command", > > but we don't have that. > > Yeah, I was thinking the same when updating the patch. > > How about adding something like PartialMatches() that checks whether > the keywords are included in the input string or not? If so, we can restrict > some tab-completion rules to operating only on MERGE, as follows. I attached > the WIP patch (0002 patch) that introduces PartialMatches(). > Is this approach over-complicated? Thought? > > + else if (PartialMatches("MERGE", "INTO", MatchAny, "USING") || > +PartialMatches("MERGE", "INTO", MatchAny, "AS", > MatchAny, "USING") || > +PartialMatches("MERGE", "INTO", MatchAny, MatchAny, > "USING")) > + { > + /* Complete MERGE INTO ... ON with target table attributes */ > + if (TailMatches("INTO", MatchAny, "USING", MatchAny, "ON")) > + COMPLETE_WITH_ATTR(prev4_wd); > + else if (TailMatches("INTO", MatchAny, "AS", MatchAny, > "USING", MatchAny, "AS", MatchAny, "ON")) > + COMPLETE_WITH_ATTR(prev8_wd); > + else if (TailMatches("INTO", MatchAny, MatchAny, "USING", > MatchAny, MatchAny, "ON")) > + COMPLETE_WITH_ATTR(prev6_wd); The patch does not apply on top of HEAD as in [1], please post a rebased patch: === Applying patches on top of PostgreSQL commit ID e351f85418313e97c203c73181757a007dfda6d0 === === applying patch ./v9-0001-psql-Improve-tab-completion-for-MERGE.patch patching file src/bin/psql/tab-complete.c Hunk #1 FAILED at 1669. Hunk #2 FAILED at 3641. Hunk #3 FAILED at 3660. Hunk #4 FAILED at 4065. 4 out of 4 hunks FAILED -- saving rejects to file src/bin/psql/tab-complete.c.rej [1] - http://cfbot.cputube.org/patch_41_3890.log Regards, Vignesh
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022-Sep-21, Fujii Masao wrote: > How about adding something like PartialMatches() that checks whether > the keywords are included in the input string or not? If so, we can restrict > some tab-completion rules to operating only on MERGE, as follows. I attached > the WIP patch (0002 patch) that introduces PartialMatches(). > Is this approach over-complicated? Thought? I think it's fine to backpatch your 0001 to 15 and put 0002 in master. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "I can't go to a restaurant and order food because I keep looking at the fonts on the menu. Five minutes later I realize that it's also talking about food" (Donald Knuth)
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022/09/21 0:51, Alvaro Herrera wrote: The rules starting at line 4111 make me a bit nervous, since nowhere we're restricting them to operating only on MERGE lines. I don't think it's a real problem since USING is not terribly common anyway. Likewise for the ones with WHEN [NOT] MATCHED. I kinda wish we had a way to search for stuff like "keyword MERGE appears earlier in the command", but we don't have that. Yeah, I was thinking the same when updating the patch. How about adding something like PartialMatches() that checks whether the keywords are included in the input string or not? If so, we can restrict some tab-completion rules to operating only on MERGE, as follows. I attached the WIP patch (0002 patch) that introduces PartialMatches(). Is this approach over-complicated? Thought? + else if (PartialMatches("MERGE", "INTO", MatchAny, "USING") || +PartialMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING") || +PartialMatches("MERGE", "INTO", MatchAny, MatchAny, "USING")) + { + /* Complete MERGE INTO ... ON with target table attributes */ + if (TailMatches("INTO", MatchAny, "USING", MatchAny, "ON")) + COMPLETE_WITH_ATTR(prev4_wd); + else if (TailMatches("INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny, "ON")) + COMPLETE_WITH_ATTR(prev8_wd); + else if (TailMatches("INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny, "ON")) + COMPLETE_WITH_ATTR(prev6_wd); Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATIONFrom 671b4dff2e259b4d148dcbfaee0611fc2bddce85 Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Wed, 21 Sep 2022 11:46:59 +0900 Subject: [PATCH 1/2] psql: Improve tab-completion for MERGE. --- src/bin/psql/tab-complete.c | 102 +++- 1 file changed, 67 insertions(+), 35 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index f3465adb85..820f47d23a 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1669,7 +1669,7 @@ psql_completion(const char *text, int start, int end) "COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE", "DELETE FROM", "DISCARD", "DO", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH", "GRANT", "IMPORT FOREIGN SCHEMA", "INSERT INTO", "LISTEN", "LOAD", "LOCK", - "MERGE", "MOVE", "NOTIFY", "PREPARE", + "MERGE INTO", "MOVE", "NOTIFY", "PREPARE", "REASSIGN", "REFRESH MATERIALIZED VIEW", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK", "SAVEPOINT", "SECURITY LABEL", "SELECT", "SET", "SHOW", "START", @@ -3641,7 +3641,7 @@ psql_completion(const char *text, int start, int end) */ else if (Matches("EXPLAIN")) COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", - "MERGE", "EXECUTE", "ANALYZE", "VERBOSE"); + "MERGE INTO", "EXECUTE", "ANALYZE", "VERBOSE"); else if (HeadMatches("EXPLAIN", "(*") && !HeadMatches("EXPLAIN", "(*)")) { @@ -3660,12 +3660,12 @@ psql_completion(const char *text, int start, int end) } else if (Matches("EXPLAIN", "ANALYZE")) COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", - "MERGE", "EXECUTE", "VERBOSE"); + "MERGE INTO", "EXECUTE", "VERBOSE"); else if (Matches("EXPLAIN", "(*)") || Matches("EXPLAIN", "VERBOSE") || Matches("EXPLAIN", "ANALYZE", "VERBOSE")) COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", - "MERGE", "EXECUTE"); + "MERGE INTO", "EXECUTE"); /* FETCH && MOVE */ @@ -4065,58 +4065,90 @@ psql_completion(const char *text, int start, int end) else if (HeadMatches("LOCK") && TailMatches("IN", "SHARE")) COMPLETE_WITH("MODE", "ROW EXCLUSIVE MODE", "UPDATE EXCLUSIVE MODE"); + + /* Complete LOCK [TABLE] [ONLY] [IN lockmode MODE] with "NOWAIT" */ + else if (HeadMatches("LOCK") && TailMatches("MODE")) + COMPLETE_WITH("NOWAIT"); + /* MERGE --- can be inside EXPLAIN */ else if (TailMatches("MERGE")) COMPLETE_WITH("INTO"); else if (TailMatches("MERGE", "INTO")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_mergetargets); + + /* Complete MERGE INTO [[AS] ] with USING */ else if (TailMatches("MERGE", "INTO", MatchAny))
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022-Sep-18, Fujii Masao wrote: > The tab-completion code for MERGE was added in the middle of that for LOCK > TABLE. > This would be an oversight of the commit that originally supported > tab-completion > for MERGE. I fixed this issue. Argh, thanks. > "MERGE" was tab-completed with just after "EXPLAIN" or "EXPLAIN ANALYZE", etc. > Since "INTO" always follows "MERGE", it's better to complete with "MERGE INTO" > there. I replaced "MERGE" with "MERGE INTO" in those tab-completions. OK, that would be similar to REFRESH MATERIALIZED VIEW. The rules starting at line 4111 make me a bit nervous, since nowhere we're restricting them to operating only on MERGE lines. I don't think it's a real problem since USING is not terribly common anyway. Likewise for the ones with WHEN [NOT] MATCHED. I kinda wish we had a way to search for stuff like "keyword MERGE appears earlier in the command", but we don't have that. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "I'm always right, but sometimes I'm more right than other times." (Linus Torvalds)
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022/09/16 11:46, bt22kawamotok wrote: Thanks for updating. + COMPLETE_WITH("UPDATE", "DELETE", "DO NOTHING"); "UPDATE" is always followed by "SET", so why not complement it with "UPDATE SET"? Thanks for reviewing. That's a good idea! I create new patch v7. Thanks for updating the patch! I applied the following changes to the patch. Attached is the updated version of the patch. The tab-completion code for MERGE was added in the middle of that for LOCK TABLE. This would be an oversight of the commit that originally supported tab-completion for MERGE. I fixed this issue. + else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny) || +TailMatches("MERGE", "INTO", MatchAny, MatchAnyExcept("AS"))) COMPLETE_WITH("USING"); This can cause to complete "MERGE INTO USING" with "USING" unexpectedly. I fixed this issue by replacing MatchAnyExcept("AS") with MatchAnyExcept("USING|AS"). I added some comments. "MERGE" was tab-completed with just after "EXPLAIN" or "EXPLAIN ANALYZE", etc. Since "INTO" always follows "MERGE", it's better to complete with "MERGE INTO" there. I replaced "MERGE" with "MERGE INTO" in those tab-completions. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATIONdiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index f3465adb85..23f2a87991 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1669,7 +1669,7 @@ psql_completion(const char *text, int start, int end) "COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE", "DELETE FROM", "DISCARD", "DO", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH", "GRANT", "IMPORT FOREIGN SCHEMA", "INSERT INTO", "LISTEN", "LOAD", "LOCK", - "MERGE", "MOVE", "NOTIFY", "PREPARE", + "MERGE INTO", "MOVE", "NOTIFY", "PREPARE", "REASSIGN", "REFRESH MATERIALIZED VIEW", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK", "SAVEPOINT", "SECURITY LABEL", "SELECT", "SET", "SHOW", "START", @@ -3641,7 +3641,7 @@ psql_completion(const char *text, int start, int end) */ else if (Matches("EXPLAIN")) COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", - "MERGE", "EXECUTE", "ANALYZE", "VERBOSE"); + "MERGE INTO", "EXECUTE", "ANALYZE", "VERBOSE"); else if (HeadMatches("EXPLAIN", "(*") && !HeadMatches("EXPLAIN", "(*)")) { @@ -3660,12 +3660,12 @@ psql_completion(const char *text, int start, int end) } else if (Matches("EXPLAIN", "ANALYZE")) COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", - "MERGE", "EXECUTE", "VERBOSE"); + "MERGE INTO", "EXECUTE", "VERBOSE"); else if (Matches("EXPLAIN", "(*)") || Matches("EXPLAIN", "VERBOSE") || Matches("EXPLAIN", "ANALYZE", "VERBOSE")) COMPLETE_WITH("SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DECLARE", - "MERGE", "EXECUTE"); + "MERGE INTO", "EXECUTE"); /* FETCH && MOVE */ @@ -4065,58 +4065,90 @@ psql_completion(const char *text, int start, int end) else if (HeadMatches("LOCK") && TailMatches("IN", "SHARE")) COMPLETE_WITH("MODE", "ROW EXCLUSIVE MODE", "UPDATE EXCLUSIVE MODE"); + + /* Complete LOCK [TABLE] [ONLY] [IN lockmode MODE] with "NOWAIT" */ + else if (HeadMatches("LOCK") && TailMatches("MODE")) + COMPLETE_WITH("NOWAIT"); + /* MERGE --- can be inside EXPLAIN */ else if (TailMatches("MERGE")) COMPLETE_WITH("INTO"); else if (TailMatches("MERGE", "INTO")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_mergetargets); + + /* Complete MERGE INTO [[AS] ] with USING */ 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)) + else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny) || +TailMatches("MERGE", "INTO", MatchAny, MatchAnyExcept("USING|AS"))) COMPLETE_WITH("USING"); - else if (TailMatches("MERGE", "INTO", MatchAny, MatchAny)) - COMPLETE_WITH("USING"); - else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING")) -
Re: [PATCH]Feature improvement for MERGE tab completion
Thanks for updating. + COMPLETE_WITH("UPDATE", "DELETE", "DO NOTHING"); "UPDATE" is always followed by "SET", so why not complement it with "UPDATE SET"? Thanks for reviewing. That's a good idea! I create new patch v7. Regards, Kotaro Kawamotodiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 62a39779b9..f899c6ab26 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 SET", "DELETE", "DO NOTHING"); else if (TailMatches("WHEN", "NOT", "MATCHED",
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022-09-14 18:12, bt22kawamotok wrote: I fixed it in v6. Thanks for updating. + COMPLETE_WITH("UPDATE", "DELETE", "DO NOTHING"); "UPDATE" is always followed by "SET", so why not complement it with "UPDATE SET"? -- Regards, -- Shinya Kato Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION
Re: [PATCH]Feature improvement for MERGE tab completion
+ 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",
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022/09/14 14:08, bt22kawamotok wrote: When I tried to apply this patch, I got the following warning, please fix it. Other than that, I think everything is fine. $ git apply fix_tab_completion_merge_v4.patch fix_tab_completion_merge_v4.patch:38: trailing whitespace. else if (TailMatches("USING", MatchAny, "ON", MatchAny) || fix_tab_completion_merge_v4.patch:39: indent with spaces. TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny) || fix_tab_completion_merge_v4.patch:40: indent with spaces. TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny)) fix_tab_completion_merge_v4.patch:53: trailing whitespace. else if (TailMatches("WHEN", "MATCHED") || warning: 4 lines add whitespace errors. Thanks for reviewing. I fixed the problem and make patch v5. Please check it. Thanks for updating the patch! + 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. 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? + 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, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION
Re: [PATCH]Feature improvement for MERGE tab completion
When I tried to apply this patch, I got the following warning, please fix it. Other than that, I think everything is fine. $ git apply fix_tab_completion_merge_v4.patch fix_tab_completion_merge_v4.patch:38: trailing whitespace. else if (TailMatches("USING", MatchAny, "ON", MatchAny) || fix_tab_completion_merge_v4.patch:39: indent with spaces. TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny) || fix_tab_completion_merge_v4.patch:40: indent with spaces. TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny)) fix_tab_completion_merge_v4.patch:53: trailing whitespace. else if (TailMatches("WHEN", "MATCHED") || warning: 4 lines add whitespace errors. Thanks for reviewing. I fixed the problem and make patch v5. Please check it. Regards, Kotaro Kawamotodiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 62a39779b9..a0332c76a4 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4063,23 +4063,28 @@ 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")) + 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); /* with [AS] alias */ - else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny)) + else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny) || + TailMatches("MERGE", "INTO", MatchAny, MatchAnyExcept("AS"))) COMPLETE_WITH("USING"); - else if (TailMatches("MERGE", "INTO", MatchAny, MatchAny)) - 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")) + else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING") || + TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); + 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 +4094,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)) + 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, "AS", MatchAny, "ON", MatchAny)) - 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",
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022-09-12 18:20, bt22kawamotok wrote: Other than this correction, the parts that can be put together in OR were corrected in fix_tab_completion_merge_v4.patch. When I tried to apply this patch, I got the following warning, please fix it. Other than that, I think everything is fine. $ git apply fix_tab_completion_merge_v4.patch fix_tab_completion_merge_v4.patch:38: trailing whitespace. else if (TailMatches("USING", MatchAny, "ON", MatchAny) || fix_tab_completion_merge_v4.patch:39: indent with spaces. TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny) || fix_tab_completion_merge_v4.patch:40: indent with spaces. TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny)) fix_tab_completion_merge_v4.patch:53: trailing whitespace. else if (TailMatches("WHEN", "MATCHED") || warning: 4 lines add whitespace errors. -- Regards, -- Shinya Kato Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION
Re: [PATCH]Feature improvement for MERGE tab completion
Other than this correction, the parts that can be put together in OR were corrected in fix_tab_completion_merge_v4.patch. Kotaro Kawamotodiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 62a39779b9..8b498f6a86 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4066,20 +4066,16 @@ psql_completion(const char *text, int start, int end) 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)) + else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny) || + (TailMatches("MERGE", "INTO", MatchAny, MatchAny) && !TailMatches("AS"))) COMPLETE_WITH("USING"); - else if (TailMatches("MERGE", "INTO", MatchAny, MatchAny)) - 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")) + else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING") || + TailMatches("MERGE", "INTO", MatchAny, MatchAny, "USING")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); /* 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) || + TailMatches("INTO", MatchAny, "AS", MatchAny, "USING", MatchAny, "AS", MatchAny) || + TailMatches("INTO", MatchAny, MatchAny, "USING", MatchAny, MatchAny)) COMPLETE_WITH("ON"); /* ON condition */ else if (TailMatches("INTO", MatchAny, "USING", MatchAny, "ON")) @@ -4089,18 +4085,19 @@ 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)) + else if (TailMatches("USING", MatchAny, "ON", MatchAny) || + TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny) || + TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny)) COMPLETE_WITH("WHEN MATCHED", "WHEN NOT MATCHED"); - else if (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny)) - 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, "AS", MatchAny, "ON", MatchAny, "WHEN") || + TailMatches("USING", MatchAny, MatchAny, "ON", 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");
Re: [PATCH]Feature improvement for MERGE tab completion
Thanks for updating! Compile errors have occurred, so can you fix them? And I think we can eliminate similar redundancies in MERGE tab completion and I would like you to fix them. For example, else if (TailMatches("WHEN", "MATCHED")) COMPLETE_WITH("THEN", "AND"); else if (TailMatches("WHEN", "NOT", "MATCHED")) COMPLETE_WITH("THEN", "AND"); above statement can be converted to the statement below. else if (TailMatches("WHEN", "MATCHED") || TailMatches("WHEN", "NOT", "MATCHED")) COMPLETE_WITH("THEN", "AND"); Sorry for making such a silly mistake. I create new path. Please reviewing. Kotaro Kawamotodiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 62a39779b9..c1e455fab1 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4068,7 +4068,7 @@ psql_completion(const char *text, int start, int end) /* 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, MatchAny) && !TailMatches("AS")) COMPLETE_WITH("USING"); else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); @@ -4095,12 +4095,16 @@ psql_completion(const char *text, int start, int end) 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("USING", MatchAny, "ON", MatchAny, "WHEN") || + TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN") || + TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) + COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("WHEN", "MATCHED")) COMPLETE_WITH("THEN", "AND"); else if (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");
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022-09-12 15:53, bt22kawamotok wrote: else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); I thought it would be better to describe this section as follows, summarizing the conditions else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN") || TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN") || TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); There are similar redundancies in the tab completion of MERGE statement, so why not fix that as well? Thanks for your review. A new patch has been created to reflect the changes you indicated. Thanks for updating! Compile errors have occurred, so can you fix them? And I think we can eliminate similar redundancies in MERGE tab completion and I would like you to fix them. For example, else if (TailMatches("WHEN", "MATCHED")) COMPLETE_WITH("THEN", "AND"); else if (TailMatches("WHEN", "NOT", "MATCHED")) COMPLETE_WITH("THEN", "AND"); above statement can be converted to the statement below. else if (TailMatches("WHEN", "MATCHED") || TailMatches("WHEN", "NOT", "MATCHED")) COMPLETE_WITH("THEN", "AND"); -- Regards, -- Shinya Kato Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION
Re: [PATCH]Feature improvement for MERGE tab completion
else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); I thought it would be better to describe this section as follows, summarizing the conditions else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN") || TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN") || TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); There are similar redundancies in the tab completion of MERGE statement, so why not fix that as well? Thanks for your review. A new patch has been created to reflect the changes you indicated. I also found a problem that "DO NOTHING" is not completed when type "WHEN MATCHED ", so I fixed it as well. Regards, Kotaro Kawamotodiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 62a39779b9..c05b52e49a 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4068,7 +4068,7 @@ psql_completion(const char *text, int start, int end) /* 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, MatchAny) && !TailMatches("AS")) COMPLETE_WITH("USING"); else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); @@ -4095,12 +4095,16 @@ psql_completion(const char *text, int start, int end) 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("USING", MatchAny, "ON", MatchAny, "WHEN")) || + (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN")) || + (TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) + COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("WHEN", "MATCHED")) COMPLETE_WITH("THEN", "AND"); else if (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");
Re: [PATCH]Feature improvement for MERGE tab completion
On 2022-09-09 11:18, bt22kawamotok wrote: I created a patch for improving MARGE tab completion. Currently there is a problem with "MERGE INTO dst as d Using src as s ON d.key = s.key WHEN " is typed, "MATCHED" and "NOT MATCHED" is not completed. There is also a problem that typing "MERGE INTO a AS " completes "USING". This patch solves the above problems. Thanks for the patch! else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); I thought it would be better to describe this section as follows, summarizing the conditions else if (TailMatches("USING", MatchAny, "ON", MatchAny, "WHEN") || TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN") || TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) COMPLETE_WITH("MATCHED", "NOT MATCHED"); There are similar redundancies in the tab completion of MERGE statement, so why not fix that as well? -- Regards, -- Shinya Kato Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION
[PATCH]Feature improvement for MERGE tab completion
Hi! I created a patch for improving MARGE tab completion. Currently there is a problem with "MERGE INTO dst as d Using src as s ON d.key = s.key WHEN " is typed, "MATCHED" and "NOT MATCHED" is not completed. There is also a problem that typing "MERGE INTO a AS " completes "USING". This patch solves the above problems. Regards, Kotaro Kawamotodiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 62a39779b9..ed1f8c5f17 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4068,7 +4068,7 @@ psql_completion(const char *text, int start, int end) /* 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, MatchAny) && !TailMatches("AS")) COMPLETE_WITH("USING"); else if (TailMatches("MERGE", "INTO", MatchAny, "AS", MatchAny, "USING")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); @@ -4095,6 +4095,12 @@ psql_completion(const char *text, int start, int end) 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("USING", MatchAny, "ON", MatchAny, "WHEN")) + COMPLETE_WITH("MATCHED", "NOT MATCHED"); + else if (TailMatches("USING", MatchAny, "AS", MatchAny, "ON", MatchAny, "WHEN")) + COMPLETE_WITH("MATCHED", "NOT MATCHED"); + else if (TailMatches("USING", MatchAny, MatchAny, "ON", MatchAny, "WHEN")) + COMPLETE_WITH("MATCHED", "NOT MATCHED"); else if (TailMatches("WHEN", "MATCHED")) COMPLETE_WITH("THEN", "AND"); else if (TailMatches("WHEN", "NOT", "MATCHED"))