v1-tab-complete-partitions
text/plain
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 */