diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index e913b83091..1d235a3987 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2998,7 +2998,7 @@ psql_completion(const char *text, int start, int end) else if (Matches1("EXECUTE")) COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements); -/* +/* * EXPLAIN [ ( option [, ...] ) ] statement * EXPLAIN [ ANALYZE ] [ VERBOSE ] statement */ @@ -3006,10 +3006,16 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_LIST8("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE", "ANALYZE", "VERBOSE", "("); else if (HeadMatches2("EXPLAIN", "(")) + { if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) COMPLETE_WITH_LIST7("ANALYZE", "VERBOSE", "COSTS", "BUFFERS", "TIMING", "SUMMARY", "FORMAT"); - else + else if (TailMatches1("FORMAT")) + COMPLETE_WITH_LIST4("TEXT", "XML", "JSON", "YAML"); + else if (TailMatches1("ANALYZE|VERBOSE|COSTS|BUFFERS|TIMING|SUMMARY")) COMPLETE_WITH_LIST4(",", ")", "ON", "OFF"); + else + COMPLETE_WITH_LIST2(",", ")"); + } else if (HeadMatches2("EXPLAIN", MatchAny) && ends_with(prev_wd, ')')) /* If the parenthesis are balanced, the list is apparently parsed as a single word */ COMPLETE_WITH_LIST5("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE"); @@ -3597,10 +3603,12 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpm, " UNION SELECT 'ANALYZE'"); else if (HeadMatches2("VACUUM", "(")) + { if (ends_with(prev_wd, ',') || ends_with(prev_wd, '(')) COMPLETE_WITH_LIST5("FULL", "FREEZE", "ANALYZE", "VERBOSE", "DISABLE_PAGE_SKIPPING"); else COMPLETE_WITH_LIST2(",", ")"); + } else if (HeadMatches1("VACUUM") && TailMatches1("(")) /* "VACUUM (" should be caught above */ COMPLETE_WITH_ATTR(prev2_wd, "");