Find attached tab completion for the following:

"... Also, recursively perform VACUUM and ANALYZE on partitions when the
command is applied to a partitioned table."
3c3bb99330aa9b4c2f6258bfa0265d806bf365c3

Add parenthesized options syntax for ANALYZE.
854dd8cff523bc17972d34772b0e39ad3d6d46a4

Add VACUUM (DISABLE_PAGE_SKIPPING) for emergencies.
ede62e56fbe809baa1a7bc3873d82f12ffe7540b

Allow multiple tables to be specified in one VACUUM or ANALYZE command.
11d8d72c27a64ea4e30adce11cf6c4f3dd3e60db
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 7bb47ea..2d7b264 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -717,6 +717,26 @@ static const SchemaQuery Query_for_list_of_tmf = {
        NULL
 };
 
+static const SchemaQuery Query_for_list_of_tpmf = {
+       /* min_server_version */
+       0,
+       /* catname */
+       "pg_catalog.pg_class c",
+       /* selcondition */
+       "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
+       CppAsString2(RELKIND_MATVIEW) ", "
+       CppAsString2(RELKIND_PARTITIONED_TABLE) ", "
+       CppAsString2(RELKIND_FOREIGN_TABLE) ")",
+       /* viscondition */
+       "pg_catalog.pg_table_is_visible(c.oid)",
+       /* namespace */
+       "c.relnamespace",
+       /* result */
+       "pg_catalog.quote_ident(c.relname)",
+       /* qualresult */
+       NULL
+};
+
 static const SchemaQuery Query_for_list_of_tpm = {
        /* min_server_version */
        0,
@@ -3563,33 +3583,41 @@ psql_completion(const char *text, int start, int end)
                COMPLETE_WITH_CONST("OPTIONS");
 
 /*
- * VACUUM [ FULL | FREEZE ] [ VERBOSE ] [ table ]
- * VACUUM [ FULL | FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
+ * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
+ * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, 
...] ]
  */
        else if (Matches1("VACUUM"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
                                                                   " UNION 
SELECT 'FULL'"
                                                                   " UNION 
SELECT 'FREEZE'"
                                                                   " UNION 
SELECT 'ANALYZE'"
+                                                                  " UNION 
SELECT '('"
                                                                   " UNION 
SELECT 'VERBOSE'");
-       else if (Matches2("VACUUM", "FULL|FREEZE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+       else if (Matches2("VACUUM", "FULL"))
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
+                                                                  " UNION 
SELECT 'FREEZE'"
                                                                   " UNION 
SELECT 'ANALYZE'"
                                                                   " UNION 
SELECT 'VERBOSE'");
-       else if (Matches3("VACUUM", "FULL|FREEZE", "ANALYZE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+       else if (Matches3("VACUUM", "FULL|FREEZE|FULL FREEZE", "ANALYZE"))
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
                                                                   " UNION 
SELECT 'VERBOSE'");
-       else if (Matches3("VACUUM", "FULL|FREEZE", "VERBOSE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+       else if (Matches3("VACUUM", "FULL|FREEZE|FULL FREEZE", "VERBOSE"))
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
                                                                   " UNION 
SELECT 'ANALYZE'");
        else if (Matches2("VACUUM", "VERBOSE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
                                                                   " UNION 
SELECT 'ANALYZE'");
        else if (Matches2("VACUUM", "ANALYZE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
                                                                   " UNION 
SELECT 'VERBOSE'");
+       else if (HeadMatches2("VACUUM", "(") && !ends_with(prev_wd, ',') && 
!ends_with(prev_wd, '('))
+                       COMPLETE_WITH_LIST2(",", ")");
+       else if (HeadMatches2("VACUUM", "(") && !ends_with(prev_wd, ')'))
+                       COMPLETE_WITH_LIST5("FULL", "FREEZE", "ANALYZE", 
"VERBOSE", "DISABLE_PAGE_SKIPPING" );
+       else if (HeadMatches1("VACUUM") && !ends_with(prev_wd, ',') && 
!ends_with(prev_wd, ')'))
+                       COMPLETE_WITH_CONST(",");
        else if (HeadMatches1("VACUUM"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL);
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, NULL);
 
 /* WITH [RECURSIVE] */
 
@@ -3600,10 +3628,24 @@ psql_completion(const char *text, int start, int end)
        else if (Matches1("WITH"))
                COMPLETE_WITH_CONST("RECURSIVE");
 
-/* ANALYZE */
+/*
+ * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ */
        /* Complete with list of tables */
+       else if (Matches2("ANALYZE", "("))
+               COMPLETE_WITH_CONST("VERBOSE)");
        else if (Matches1("ANALYZE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf, NULL);
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
+                               " UNION SELECT 'VERBOSE'"
+                               " UNION SELECT '('"
+                               );
+       else if (HeadMatches1("ANALYZE") &&
+                       !ends_with(prev_wd, ',') &&
+                       !strcasecmp(prev_wd, "VERBOSE"))
+                       COMPLETE_WITH_CONST(",");
+       else if (HeadMatches1("ANALYZE"))
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, NULL);
 
 /* WHERE */
        /* Simple case of the word before the where being the table name */

Reply via email to