aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-01-28 15:30:14 +0900
committerMichael Paquier <michael@paquier.xyz>2019-01-28 15:30:14 +0900
commit23349b18d92d0dd522da17917bb5231f37a87d88 (patch)
tree726bed0ad2934466cbb67305bd89562147c1f2e5 /src
parenta23676503b746b7f1588cd2ab0c60411032d32da (diff)
downloadpostgresql-23349b18d92d0dd522da17917bb5231f37a87d88.tar.gz
postgresql-23349b18d92d0dd522da17917bb5231f37a87d88.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/tab-complete.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 292b1f483a9..3361c8394d8 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -583,6 +583,17 @@ static const SchemaQuery Query_for_list_of_statistics = {
" OR '\"' || relname || '\"'='%s') "\
" AND pg_catalog.pg_table_is_visible(c.oid)"
+#define Query_for_list_of_attribute_numbers \
+"SELECT attnum "\
+" FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c "\
+" WHERE c.oid = a.attrelid "\
+" AND a.attnum > 0 "\
+" AND NOT a.attisdropped "\
+" AND substring(attnum::pg_catalog.text,1,%d)='%s' "\
+" AND (pg_catalog.quote_ident(relname)='%s' "\
+" OR '\"' || relname || '\"'='%s') "\
+" AND pg_catalog.pg_table_is_visible(c.oid)"
+
#define Query_for_list_of_attributes_with_schema \
"SELECT pg_catalog.quote_ident(attname) "\
" 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)
/* ALTER INDEX <name> ALTER */
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER"))
COMPLETE_WITH("COLUMN");
+ /* ALTER INDEX <name> ALTER COLUMN */
+ else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN"))
+ {
+ completion_info_charp = prev3_wd;
+ COMPLETE_WITH_QUERY(Query_for_list_of_attribute_numbers);
+ }
/* ALTER INDEX <name> ALTER COLUMN <colnum> */
else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny))
COMPLETE_WITH("SET STATISTICS");