Skip to content

Commit 23349b1

Browse files
committed
Add tab completion for ALTER INDEX ALTER COLUMN in psql
The completion here consists of attribute numbers, which is specific to this grammar. Author: Tatsuro Yamada Reviewed-by: Peter Eisentraut Discussion: https://portgr.es/m/b58a78fa-81ce-186f-f0bc-c1aa93c46cbf@lab.ntt.co.jp
1 parent a236765 commit 23349b1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/bin/psql/tab-complete.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,17 @@ static const SchemaQuery Query_for_list_of_statistics = {
583583
" OR '\"' || relname || '\"'='%s') "\
584584
" AND pg_catalog.pg_table_is_visible(c.oid)"
585585

586+
#define Query_for_list_of_attribute_numbers \
587+
"SELECT attnum "\
588+
" FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c "\
589+
" WHERE c.oid = a.attrelid "\
590+
" AND a.attnum > 0 "\
591+
" AND NOT a.attisdropped "\
592+
" AND substring(attnum::pg_catalog.text,1,%d)='%s' "\
593+
" AND (pg_catalog.quote_ident(relname)='%s' "\
594+
" OR '\"' || relname || '\"'='%s') "\
595+
" AND pg_catalog.pg_table_is_visible(c.oid)"
596+
586597
#define Query_for_list_of_attributes_with_schema \
587598
"SELECT pg_catalog.quote_ident(attname) "\
588599
" FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c, pg_catalog.pg_namespace n "\
@@ -1604,6 +1615,12 @@ psql_completion(const char *text, int start, int end)
16041615
/* ALTER INDEX <name> ALTER */
16051616
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER"))
16061617
COMPLETE_WITH("COLUMN");
1618+
/* ALTER INDEX <name> ALTER COLUMN */
1619+
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN"))
1620+
{
1621+
completion_info_charp = prev3_wd;
1622+
COMPLETE_WITH_QUERY(Query_for_list_of_attribute_numbers);
1623+
}
16071624
/* ALTER INDEX <name> ALTER COLUMN <colnum> */
16081625
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny))
16091626
COMPLETE_WITH("SET STATISTICS");

0 commit comments

Comments
 (0)