postgres.git / summary / log / commit / refs

commit    1f75b454134cce6a67a9bcdb01b5c018221dd359
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Tue Aug 11 05:37:38 2020 +0000

    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


src/bin/psql/tab-complete.c | 38 +++++++++++++++++++++++++++++--------- 1 file 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")) [parent: 1784f278a638]