aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2020-08-11 14:37:38 +0900
committerMichael Paquier <michael@paquier.xyz>2020-08-11 14:37:38 +0900
commit1f75b454134cce6a67a9bcdb01b5c018221dd359 (patch)
treee7e479990bf17469276524eb7cb755b0ccb444db
parent1784f278a63866cc144fcd0a2127cadba6a2b7f8 (diff)
downloadpostgresql-1f75b454134cce6a67a9bcdb01b5c018221dd359.tar.gz
postgresql-1f75b454134cce6a67a9bcdb01b5c018221dd359.zip
Improve tab completion of REINDEX in psql
This allows the tab completion of REINDEX to handle an optional parenthesized list of options. This case is more complicated than VACUUM or ANALYZE because of CONCURRENTLY and the different object types to consider with the reindex. Author: Justin Pryzby Reviewed-by: Alexey Kondratov, Michael Paquier Discussion: https://postgr.es/m/20200403182712.GR14618@telsasoft.com
-rw-r--r--src/bin/psql/tab-complete.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index c4af40bfa9f..f41785f11c1 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3430,28 +3430,48 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("DATA");
/* REINDEX */
- else if (Matches("REINDEX"))
+ else if (Matches("REINDEX") ||
+ Matches("REINDEX", "(*)"))
COMPLETE_WITH("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE");
- else if (Matches("REINDEX", "TABLE"))
+ else if (Matches("REINDEX", "TABLE") ||
+ Matches("REINDEX", "(*)", "TABLE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables,
" UNION SELECT 'CONCURRENTLY'");
- else if (Matches("REINDEX", "INDEX"))
+ else if (Matches("REINDEX", "INDEX") ||
+ Matches("REINDEX", "(*)", "INDEX"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,
" UNION SELECT 'CONCURRENTLY'");
- else if (Matches("REINDEX", "SCHEMA"))
+ else if (Matches("REINDEX", "SCHEMA") ||
+ Matches("REINDEX", "(*)", "SCHEMA"))
COMPLETE_WITH_QUERY(Query_for_list_of_schemas
" UNION SELECT 'CONCURRENTLY'");
- else if (Matches("REINDEX", "SYSTEM|DATABASE"))
+ else if (Matches("REINDEX", "SYSTEM|DATABASE") ||
+ Matches("REINDEX", "(*)", "SYSTEM|DATABASE"))
COMPLETE_WITH_QUERY(Query_for_list_of_databases
" UNION SELECT 'CONCURRENTLY'");
- else if (Matches("REINDEX", "TABLE", "CONCURRENTLY"))
+ else if (Matches("REINDEX", "TABLE", "CONCURRENTLY") ||
+ Matches("REINDEX", "(*)", "TABLE", "CONCURRENTLY"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables, NULL);
- else if (Matches("REINDEX", "INDEX", "CONCURRENTLY"))
+ else if (Matches("REINDEX", "INDEX", "CONCURRENTLY") ||
+ Matches("REINDEX", "(*)", "INDEX", "CONCURRENTLY"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
- else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY"))
+ else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY") ||
+ Matches("REINDEX", "(*)", "SCHEMA", "CONCURRENTLY"))
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
- else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY"))
+ else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY") ||
+ Matches("REINDEX", "(*)", "SYSTEM|DATABASE", "CONCURRENTLY"))
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
+ else if (HeadMatches("REINDEX", "(*") &&
+ !HeadMatches("REINDEX", "(*)"))
+ {
+ /*
+ * This fires if we're in an unfinished parenthesized option list.
+ * get_previous_words treats a completed parenthesized option list as
+ * one word, so the above test is correct.
+ */
+ if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
+ COMPLETE_WITH("VERBOSE");
+ }
/* SECURITY LABEL */
else if (Matches("SECURITY"))