diff --git a/doc/src/sgml/ref/alter_index.sgml b/doc/src/sgml/ref/alter_index.sgml
new file mode 100644
index 0000000000..3eaf0f7291
--- /dev/null
+++ b/doc/src/sgml/ref/alter_index.sgml
@@ -0,0 +1,188 @@
+
+
+
+
+ ALTER INDEX
+ SQL - Language Statements
+
+
+
+ ALTER INDEX
+ change the definition of an index
+
+
+
+ ALTER INDEX
+
+
+
+
+ALTER INDEX name
+ action [, ... ]
+ALTER INDEX name
+ RENAME TO new_name
+
+where action is one of:
+
+ OWNER TO new_owner
+ SET INDEXSPACE indexspace_name
+
+
+
+
+ Description
+
+
+ ALTER INDEX changes the definition of an existing index.
+ There are several subforms:
+
+
+
+
+ OWNER
+
+
+ This form changes the owner of the index to the
+ specified user.
+
+
+
+
+
+ SET TABLESPACE
+
+
+ This form changes the index's tablespace to the specified tablespace and
+ moves the data file(s) associated with the index to the new tablespace.
+ See also
+ .
+
+
+
+
+
+ RENAME
+
+
+ The RENAME forms change the name of the index.
+ There is no effect on the stored data.
+
+
+
+
+
+
+
+
+ All the actions except RENAME can be combined into
+ a list of multiple alterations to apply in parallel.
+
+
+
+
+
+ Parameters
+
+
+
+
+ name
+
+
+ The name (possibly schema-qualified) of an existing index to
+ alter.
+
+
+
+
+
+
+ new_name
+
+
+ New name for the index.
+
+
+
+
+
+
+ new_owner
+
+
+ The user name of the new owner of the index.
+
+
+
+
+
+ tablespace_name
+
+
+ The tablespace name to which the index will be moved.
+
+
+
+
+
+
+
+
+ Notes
+
+
+ This same operations are supported by ALTER TABLE>. See also
+ .
+
+
+
+ Changing any part of a system catalog index is not permitted.
+
+
+
+
+ Examples
+
+ To rename an existing index:
+
+ALTER INDEX distributors RENAME TO suppliers;
+
+
+
+
+ To move a index to a different tablespace:
+
+ALTER INDEX distributors SET TABLESPACE fasttablespace;
+
+
+
+
+
+
+ Compatibility
+
+
+ ALTER INDEX> is a PostgreSQL extension.
+
+
+
+
+
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e8bc3cf5ad..5240a69dd2 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.471 2004/08/12 21:00:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.472 2004/08/20 04:29:32 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -156,8 +156,8 @@ static void doNegateFloat(Value *v);
%type alter_column_default opclass_item alter_using
%type add_drop
-%type alter_table_cmd
-%type alter_table_cmds
+%type alter_table_cmd alter_rel_cmd
+%type alter_table_cmds alter_rel_cmds
%type opt_drop_behavior
@@ -1138,7 +1138,7 @@ CheckPointStmt:
/*****************************************************************************
*
- * ALTER TABLE variations
+ * ALTER [ TABLE | INDEX ] variations
*
*****************************************************************************/
@@ -1148,6 +1148,15 @@ AlterTableStmt:
AlterTableStmt *n = makeNode(AlterTableStmt);
n->relation = $3;
n->cmds = $4;
+ n->relkind = OBJECT_TABLE;
+ $$ = (Node *)n;
+ }
+ | ALTER INDEX relation_expr alter_rel_cmds
+ {
+ AlterTableStmt *n = makeNode(AlterTableStmt);
+ n->relation = $3;
+ n->cmds = $4;
+ n->relkind = OBJECT_INDEX;
$$ = (Node *)n;
}
;
@@ -1262,14 +1271,6 @@ alter_table_cmd:
n->subtype = AT_ToastTable;
$$ = (Node *)n;
}
- /* ALTER TABLE OWNER TO UserId */
- | OWNER TO UserId
- {
- AlterTableCmd *n = makeNode(AlterTableCmd);
- n->subtype = AT_ChangeOwner;
- n->name = $3;
- $$ = (Node *)n;
- }
/* ALTER TABLE CLUSTER ON */
| CLUSTER ON name
{
@@ -1286,7 +1287,27 @@ alter_table_cmd:
n->name = NULL;
$$ = (Node *)n;
}
- /* ALTER TABLE SET TABLESPACE */
+ | alter_rel_cmd
+ {
+ $$ = $1;
+ }
+ ;
+
+alter_rel_cmds: alter_rel_cmd { $$ = list_make1($1); }
+ | alter_rel_cmds ',' alter_rel_cmd { $$ = lappend($1, $3); }
+ ;
+
+
+alter_rel_cmd:
+ /* ALTER [ TABLE | INDEX ] OWNER TO UserId */
+ OWNER TO UserId
+ {
+ AlterTableCmd *n = makeNode(AlterTableCmd);
+ n->subtype = AT_ChangeOwner;
+ n->name = $3;
+ $$ = (Node *)n;
+ }
+ /* ALTER [ TABLE | INDEX ] SET TABLESPACE */
| SET TABLESPACE name
{
AlterTableCmd *n = makeNode(AlterTableCmd);
@@ -1319,6 +1340,8 @@ alter_using:
| /* EMPTY */ { $$ = NULL; }
;
+
+
/*****************************************************************************
*
* QUERY :
@@ -3660,6 +3683,15 @@ RenameStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' RENAME TO name
n->newname = $6;
$$ = (Node *)n;
}
+ | ALTER INDEX relation_expr RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_INDEX;
+ n->relation = $3;
+ n->subname = NULL;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
| ALTER TABLE relation_expr RENAME opt_column name TO name
{
RenameStmt *n = makeNode(RenameStmt);
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 0fff253a61..b8c853c0f3 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.225 2004/08/12 21:00:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.226 2004/08/20 04:29:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1269,6 +1269,9 @@ CreateCommandTag(Node *parsetree)
case OBJECT_GROUP:
tag = "ALTER GROUP";
break;
+ case OBJECT_INDEX:
+ tag = "ALTER INDEX";
+ break;
case OBJECT_LANGUAGE:
tag = "ALTER LANGUAGE";
break;
@@ -1331,9 +1334,21 @@ CreateCommandTag(Node *parsetree)
break;
case T_AlterTableStmt:
- tag = "ALTER TABLE";
- break;
+ {
+ AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
+ /*
+ * We might be supporting ALTER INDEX here, so
+ * set the completion table appropriately.
+ * Catch all other possibilities with ALTER TABLE
+ */
+
+ if(stmt->relkind == OBJECT_INDEX)
+ tag = "ALTER INDEX";
+ else
+ tag = "ALTER TABLE";
+ }
+ break;
case T_AlterDomainStmt:
tag = "ALTER DOMAIN";
break;
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 130fcd33f4..1b036be842 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.109 2004/07/28 14:23:30 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.110 2004/08/20 04:29:32 momjian Exp $
*/
/*----------------------------------------------------------------------
@@ -632,7 +632,8 @@ psql_completion(char *text, int start, int end)
pg_strcasecmp(prev3_wd, "TABLE") != 0)
{
static const char *const list_ALTER[] =
- {"DATABASE", "GROUP", "SCHEMA", "TABLE", "TRIGGER", "USER", NULL};
+ {"DATABASE", "GROUP", "SCHEMA", "TABLE", "TRIGGER", "USER", "INDEX",
+ NULL};
COMPLETE_WITH_LIST(list_ALTER);
}
@@ -646,6 +647,16 @@ psql_completion(char *text, int start, int end)
COMPLETE_WITH_LIST(list_ALTERDATABASE);
}
+ /* ALTER INDEX */
+ else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
+ pg_strcasecmp(prev2_wd, "INDEX") == 0)
+ {
+ static const char *const list_ALTERINDEX[] =
+ {"SET TABLESPACE", "OWNER TO", "RENAME TO", NULL};
+
+ COMPLETE_WITH_LIST(list_ALTERINDEX);
+ }
+
/* ALTER TRIGGER , add ON */
else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index aff28bea08..862b2572d9 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.266 2004/08/19 20:57:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.267 2004/08/20 04:29:33 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -797,6 +797,7 @@ typedef struct AlterTableStmt
NodeTag type;
RangeVar *relation; /* table to work on */
List *cmds; /* list of subcommands */
+ ObjectType relkind; /* type of object */
} AlterTableStmt;
typedef enum AlterTableType