]> granicus.if.org Git - postgresql/blobdiff - src/bin/psql/tab-complete.c
Add a "SQLSTATE-only" error verbosity option to libpq and psql.
[postgresql] / src / bin / psql / tab-complete.c
index 7b7a88fda34940b7065b12f3752d30a925764876..7c4e5fbacbe6cb4743f3e804a4eace898b2f059e 100644 (file)
@@ -1039,6 +1039,7 @@ static const char *const table_storage_parameters[] = {
        "toast.log_autovacuum_min_duration",
        "toast_tuple_target",
        "user_catalog_table",
+       "vacuum_index_cleanup",
        NULL
 };
 
@@ -2065,15 +2066,21 @@ psql_completion(const char *text, int start, int end)
 /*
  * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
  * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
- *
- * Currently the only allowed option is VERBOSE, so we can be skimpier on
- * the option processing than VACUUM has to be.
  */
        else if (Matches("ANALYZE"))
                COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_analyzables,
                                                                   " UNION SELECT 'VERBOSE'");
-       else if (Matches("ANALYZE", "("))
-               COMPLETE_WITH("VERBOSE)");
+       else if (HeadMatches("ANALYZE", "(*") &&
+                        !HeadMatches("ANALYZE", "(*)"))
+       {
+               /*
+                * 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", "SKIP_LOCKED");
+       }
        else if (HeadMatches("ANALYZE") && TailMatches("("))
                /* "ANALYZE (" should be caught above, so assume we want columns */
                COMPLETE_WITH_ATTR(prev2_wd, "");
@@ -2085,16 +2092,18 @@ psql_completion(const char *text, int start, int end)
                COMPLETE_WITH("WORK", "TRANSACTION", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE");
 /* END, ABORT */
        else if (Matches("END|ABORT"))
-               COMPLETE_WITH("WORK", "TRANSACTION");
+               COMPLETE_WITH("AND", "WORK", "TRANSACTION");
 /* COMMIT */
        else if (Matches("COMMIT"))
-               COMPLETE_WITH("WORK", "TRANSACTION", "PREPARED");
+               COMPLETE_WITH("AND", "WORK", "TRANSACTION", "PREPARED");
 /* RELEASE SAVEPOINT */
        else if (Matches("RELEASE"))
                COMPLETE_WITH("SAVEPOINT");
 /* ROLLBACK */
        else if (Matches("ROLLBACK"))
-               COMPLETE_WITH("WORK", "TRANSACTION", "TO SAVEPOINT", "PREPARED");
+               COMPLETE_WITH("AND", "WORK", "TRANSACTION", "TO SAVEPOINT", "PREPARED");
+       else if (Matches("ABORT|END|COMMIT|ROLLBACK", "AND"))
+               COMPLETE_WITH("CHAIN");
 /* CALL */
        else if (Matches("CALL"))
                COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures, NULL);
@@ -2424,7 +2433,7 @@ psql_completion(const char *text, int start, int end)
        else if (Matches("CREATE", "STATISTICS", MatchAny))
                COMPLETE_WITH("(", "ON");
        else if (Matches("CREATE", "STATISTICS", MatchAny, "("))
-               COMPLETE_WITH("ndistinct", "dependencies");
+               COMPLETE_WITH("ndistinct", "dependencies", "mcv");
        else if (Matches("CREATE", "STATISTICS", MatchAny, "(*)"))
                COMPLETE_WITH("ON");
        else if (HeadMatches("CREATE", "STATISTICS", MatchAny) &&
@@ -3205,12 +3214,24 @@ psql_completion(const char *text, int start, int end)
        else if (Matches("REINDEX"))
                COMPLETE_WITH("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE");
        else if (Matches("REINDEX", "TABLE"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables, NULL);
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables,
+                                                                  " UNION SELECT 'CONCURRENTLY'");
        else if (Matches("REINDEX", "INDEX"))
-               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,
+                                                                  " UNION SELECT 'CONCURRENTLY'");
        else if (Matches("REINDEX", "SCHEMA"))
-               COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+               COMPLETE_WITH_QUERY(Query_for_list_of_schemas
+                                                       " UNION SELECT 'CONCURRENTLY'");
        else if (Matches("REINDEX", "SYSTEM|DATABASE"))
+               COMPLETE_WITH_QUERY(Query_for_list_of_databases
+                                                       " UNION SELECT 'CONCURRENTLY'");
+       else if (Matches("REINDEX", "TABLE", "CONCURRENTLY"))
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables, NULL);
+       else if (Matches("REINDEX", "INDEX", "CONCURRENTLY"))
+               COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
+       else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY"))
+               COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+       else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY"))
                COMPLETE_WITH_QUERY(Query_for_list_of_databases);
 
 /* SECURITY LABEL */
@@ -3423,7 +3444,10 @@ psql_completion(const char *text, int start, int end)
                 */
                if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
                        COMPLETE_WITH("FULL", "FREEZE", "ANALYZE", "VERBOSE",
-                                                 "DISABLE_PAGE_SKIPPING");
+                                                 "DISABLE_PAGE_SKIPPING", "SKIP_LOCKED",
+                                                 "INDEX_CLEANUP");
+               else if (TailMatches("FULL|FREEZE|ANALYZE|VERBOSE|DISABLE_PAGE_SKIPPING|SKIP_LOCKED|INDEX_CLEANUP"))
+                       COMPLETE_WITH("ON", "OFF");
        }
        else if (HeadMatches("VACUUM") && TailMatches("("))
                /* "VACUUM (" should be caught above, so assume we want columns */
@@ -3628,7 +3652,7 @@ psql_completion(const char *text, int start, int end)
                else if (TailMatchesCS("SHOW_CONTEXT"))
                        COMPLETE_WITH_CS("never", "errors", "always");
                else if (TailMatchesCS("VERBOSITY"))
-                       COMPLETE_WITH_CS("default", "verbose", "terse");
+                       COMPLETE_WITH_CS("default", "verbose", "terse", "sqlstate");
        }
        else if (TailMatchesCS("\\sf*"))
                COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_routines, NULL);
@@ -4307,7 +4331,7 @@ exec_query(const char *query)
        if (PQresultStatus(result) != PGRES_TUPLES_OK)
        {
 #ifdef NOT_USED
-               psql_error("tab completion query failed: %s\nQuery was:\n%s\n",
+               pg_log_error("tab completion query failed: %s\nQuery was:\n%s",
                                   PQerrorMessage(pset.db), query);
 #endif
                PQclear(result);