Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 45a2d45

Browse files
committed
Fix bogus tab-completion rule for CREATE PUBLICATION.
You can't use "FOR TABLE" as a single Matches argument, because readline will consider that input to be two words not one. It's necessary to make the pattern contain two arguments. The case accidentally worked anyway because the words_after_create test fired ... but only for the first such table name. Noted by Edmund Horner, though this isn't exactly his proposed fix. Backpatch to v10 where the faulty code came in. Discussion: https://postgr.es/m/CAMyN-kDe=gBmHgxWwUUaXuwK+p+7g1vChR7foPHRDLE592nJPQ@mail.gmail.com
1 parent ec7b276 commit 45a2d45

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/bin/psql/tab-complete.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,21 @@ psql_completion(const char *text, int start, int end)
16001600
word_matches(p2, previous_words[previous_words_count - 2]) && \
16011601
word_matches(p3, previous_words[previous_words_count - 3]))
16021602

1603+
#define HeadMatches4(p1, p2, p3, p4) \
1604+
(previous_words_count >= 4 && \
1605+
word_matches(p1, previous_words[previous_words_count - 1]) && \
1606+
word_matches(p2, previous_words[previous_words_count - 2]) && \
1607+
word_matches(p3, previous_words[previous_words_count - 3]) && \
1608+
word_matches(p4, previous_words[previous_words_count - 4]))
1609+
1610+
#define HeadMatches5(p1, p2, p3, p4, p5) \
1611+
(previous_words_count >= 5 && \
1612+
word_matches(p1, previous_words[previous_words_count - 1]) && \
1613+
word_matches(p2, previous_words[previous_words_count - 2]) && \
1614+
word_matches(p3, previous_words[previous_words_count - 3]) && \
1615+
word_matches(p4, previous_words[previous_words_count - 4]) && \
1616+
word_matches(p5, previous_words[previous_words_count - 5]))
1617+
16031618
/* Known command-starting keywords. */
16041619
static const char *const sql_commands[] = {
16051620
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CALL", "CHECKPOINT", "CLOSE", "CLUSTER",
@@ -2646,8 +2661,8 @@ psql_completion(const char *text, int start, int end)
26462661
COMPLETE_WITH_LIST3("FOR TABLE", "FOR ALL TABLES", "WITH (");
26472662
else if (Matches4("CREATE", "PUBLICATION", MatchAny, "FOR"))
26482663
COMPLETE_WITH_LIST2("TABLE", "ALL TABLES");
2649-
/* Complete "CREATE PUBLICATION <name> FOR TABLE <table>" */
2650-
else if (Matches4("CREATE", "PUBLICATION", MatchAny, "FOR TABLE"))
2664+
/* Complete "CREATE PUBLICATION <name> FOR TABLE <table>, ..." */
2665+
else if (HeadMatches5("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE"))
26512666
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
26522667
/* Complete "CREATE PUBLICATION <name> [...] WITH" */
26532668
else if (HeadMatches2("CREATE", "PUBLICATION") && TailMatches2("WITH", "("))

0 commit comments

Comments
 (0)