On 2018/12/26 14:50, Tatsuro Yamada wrote:
On 2018/12/26 14:15, Michael Paquier wrote:
On Wed, Dec 26, 2018 at 02:05:26PM +0900, Tatsuro Yamada wrote:
Do you mean my "fix_manual_of_alter_index_v2.patch"?
Nope. This patch is only a proposal for the documentation. The main
patch to extend psql completion so as column numbers are suggested
fails to apply.
I rebased the WIP patch. :)
* Following query is added to get attribute numbers of index,
however its result contains not only expression columns but also other
columns.
* I'm not sure what should I use "%d" and first "%s" in the query, so I
commented out: /* %d %s */.
I know this is ugly.. Do you know how to use?
+#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 "\
+" /* %d %s */" \
+" AND a.attrelid = (select oid from pg_catalog.pg_class where relname = '%s')
"\
+" AND pg_catalog.pg_table_is_visible(c.oid) "\
+"order by a.attnum asc "
I modified the patch to remove unusable condition.
========
# create table hoge (a integer, b integer, c integer);
# create index ind_hoge on hoge(a, b, c, (c*1), (c*2), (c*3), (c*4), (c*5),
(c*6), (c*7), (c*8), (c*9));
# \d ind_hoge
Index "public.ind_hoge"
Column | Type | Key? | Definition
--------+---------+------+------------
a | integer | yes | a
b | integer | yes | b
c | integer | yes | c
expr | integer | yes | (c * 1)
expr1 | integer | yes | (c * 2)
expr2 | integer | yes | (c * 3)
expr3 | integer | yes | (c * 4)
expr4 | integer | yes | (c * 5)
expr5 | integer | yes | (c * 6)
expr6 | integer | yes | (c * 7)
expr7 | integer | yes | (c * 8)
expr8 | integer | yes | (c * 9)
btree, for table "public.hoge"
# alter index ind_hoge alter column <tab!>
1 10 11 12 2 3 4 5 6 7 8 9
# alter index ind_hoge alter column 1 <tab!>
1 10 11 12
# alter index ind_hoge alter column 10 <tab!>
alter index ind_hoge alter COLUMN 10 SET STATISTICS
========
Thanks,
Tatsuro Yamada
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 91df96e796..a0e71550e2 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -583,6 +583,18 @@ 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 "\
+" /* %d %s */" \
+" AND a.attrelid = (select oid from pg_catalog.pg_class where relname = '%s') "\
+" AND pg_catalog.pg_table_is_visible(c.oid) "\
+"order by a.attnum asc "
+
#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 +1616,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");