Hi,
Attached patches are following:
* tab_completion_alter_index_set_statistics.patch
- Add column name completion after ALTER COLUMN
- Avoid schema completion after SET STATISTICS
* fix_manual_of_alter_index.patch
- ALTER INDEX ALTER COLUMN syntax is able to use not only
column number but also column name. So, I fixed the manual.
* tab_completion_alter_table_set_statistics.patch
- Avoid schema completion after SET STATISTICS
Regards,
Tatsuro Yamada
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 9dbd555166..31f4b7d862 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1554,9 +1554,18 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("PARTITION");
else if (Matches("ALTER", "INDEX", MatchAny, "ATTACH", "PARTITION"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
- /* ALTER INDEX <name> ALTER COLUMN <colnum> */
- else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny))
+ /* ALTER INDEX <name> ALTER [COLUMN] */
+ else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN") ||
+ Matches("ALTER", "INDEX", MatchAny, "ALTER"))
+ COMPLETE_WITH_ATTR(prev3_wd, "");
+ /* ALTER INDEX <name> ALTER [COLUMN] <colname> */
+ else if (Matches("ALTER", "INDEX", MatchAny, "ALTER", "COLUMN", MatchAny) ||
+ Matches("ALTER", "INDEX", MatchAny, "ALTER", MatchAny))
COMPLETE_WITH("SET STATISTICS");
+ /* ALTER INDEX <name> ALTER COLUMN <colname> SET STATISTICS */
+ else if (HeadMatches("ALTER", "INDEX") && TailMatches("SET", "STATISTICS")){
+ /* We don't complete after "SET STATISTICS" */
+ }
/* ALTER INDEX <name> SET */
else if (Matches("ALTER", "INDEX", MatchAny, "SET"))
COMPLETE_WITH("(", "TABLESPACE");
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 9dbd555166..2f041350fa 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1858,6 +1858,10 @@ psql_completion(const char *text, int start, int end)
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "(") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "("))
COMPLETE_WITH("n_distinct", "n_distinct_inherited");
+ /* ALTER TABLE ALTER [COLUMN] <foo> SET STATISTICS */
+ else if (HeadMatches("ALTER", "TABLE") && TailMatches("SET", "STATISTICS")){
+ /* We don't complete after "SET STATISTICS" */
+ }
/* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STORAGE") ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STORAGE"))
diff --git a/doc/src/sgml/ref/alter_index.sgml b/doc/src/sgml/ref/alter_index.sgml
index 6d34dbb74e..1b5b1f7ef1 100644
--- a/doc/src/sgml/ref/alter_index.sgml
+++ b/doc/src/sgml/ref/alter_index.sgml
@@ -27,7 +27,7 @@ ALTER INDEX <replaceable class="parameter">name</replaceable> ATTACH PARTITION <
ALTER INDEX <replaceable class="parameter">name</replaceable> DEPENDS ON EXTENSION <replaceable class="parameter">extension_name</replaceable>
ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">storage_parameter</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )
ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET ( <replaceable class="parameter">storage_parameter</replaceable> [, ... ] )
-ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable>
+ALTER INDEX [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable> | <replaceable class="parameter">column_name</replaceable>
SET STATISTICS <replaceable class="parameter">integer</replaceable>
ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable> [ OWNED BY <replaceable class="parameter">role_name</replaceable> [, ... ] ]
SET TABLESPACE <replaceable class="parameter">new_tablespace</replaceable> [ NOWAIT ]
@@ -137,14 +137,12 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
</varlistentry>
<varlistentry>
- <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_number</replaceable> SET STATISTICS <replaceable class="parameter">integer</replaceable></literal></term>
+ <term><literal>ALTER [ COLUMN ] <replaceable class="parameter">column_number | column_name</replaceable> SET STATISTICS <replaceable class="parameter">integer</replaceable></literal></term>
<listitem>
<para>
This form sets the per-column statistics-gathering target for
subsequent <xref linkend="sql-analyze"/> operations, though can
be used only on index columns that are defined as an expression.
- Since expressions lack a unique name, we refer to them using the
- ordinal number of the index column.
The target can be set in the range 0 to 10000; alternatively, set it
to -1 to revert to using the system default statistics
target (<xref linkend="guc-default-statistics-target"/>).
@@ -175,6 +173,15 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><replaceable class="parameter">column_name</replaceable></term>
+ <listitem>
+ <para>
+ The name of an existing index column.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><replaceable class="parameter">column_number</replaceable></term>
<listitem>