Index: doc/src/sgml/ref/alter_index.sgml
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/doc/src/sgml/ref/alter_index.sgml,v
retrieving revision 1.1
diff -2 -c -r1.1 alter_index.sgml
*** doc/src/sgml/ref/alter_index.sgml 13 Aug 2004 04:32:27 -0000 1.1
--- doc/src/sgml/ref/alter_index.sgml 13 Aug 2004 06:35:17 -0000
***************
*** 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 indexspace:
+
+ ALTER INDEX distributors SET INDEXSPACE fastindexspace;
+
+
+
+
+
+
+ Compatibility
+
+
+ ALTER INDEX> is a PostgreSQL extension.
+
+
+
+
+
Index: src/backend/parser/gram.y
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/backend/parser/gram.y,v
retrieving revision 2.469
diff -2 -c -r2.469 gram.y
*** src/backend/parser/gram.y 2 Aug 2004 04:26:35 -0000 2.469
--- src/backend/parser/gram.y 13 Aug 2004 03:50:25 -0000
***************
*** 157,162 ****
%type add_drop
! %type alter_table_cmd
! %type alter_table_cmds
%type opt_drop_behavior
--- 157,162 ----
%type add_drop
! %type alter_table_cmd alter_rel_cmd
! %type alter_table_cmds alter_rel_cmds
%type opt_drop_behavior
***************
*** 1139,1143 ****
/*****************************************************************************
*
! * ALTER TABLE variations
*
*****************************************************************************/
--- 1139,1143 ----
/*****************************************************************************
*
! * ALTER [ TABLE | INDEX ] variations
*
*****************************************************************************/
***************
*** 1149,1152 ****
--- 1149,1161 ----
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;
}
***************
*** 1263,1274 ****
$$ = (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
--- 1272,1275 ----
***************
*** 1287,1291 ****
$$ = (Node *)n;
}
! /* ALTER TABLE SET TABLESPACE */
| SET TABLESPACE name
{
--- 1288,1312 ----
$$ = (Node *)n;
}
! | 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
{
***************
*** 1320,1323 ****
--- 1341,1346 ----
;
+
+
/*****************************************************************************
*
***************
*** 3656,3659 ****
--- 3679,3691 ----
RenameStmt *n = makeNode(RenameStmt);
n->renameType = OBJECT_TABLE;
+ n->relation = $3;
+ n->subname = NULL;
+ 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;
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/backend/tcop/utility.c,v
retrieving revision 1.223
diff -2 -c -r1.223 utility.c
*** src/backend/tcop/utility.c 2 Aug 2004 01:30:45 -0000 1.223
--- src/backend/tcop/utility.c 13 Aug 2004 03:52:06 -0000
***************
*** 1272,1275 ****
--- 1272,1278 ----
tag = "ALTER GROUP";
break;
+ case OBJECT_INDEX:
+ tag = "ALTER INDEX";
+ break;
case OBJECT_LANGUAGE:
tag = "ALTER LANGUAGE";
***************
*** 1334,1340 ****
case T_AlterTableStmt:
! tag = "ALTER TABLE";
! break;
case T_AlterDomainStmt:
tag = "ALTER DOMAIN";
--- 1337,1355 ----
case T_AlterTableStmt:
! {
! 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";
Index: src/bin/psql/tab-complete.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/tab-complete.c,v
retrieving revision 1.109
diff -2 -c -r1.109 tab-complete.c
*** src/bin/psql/tab-complete.c 28 Jul 2004 14:23:30 -0000 1.109
--- src/bin/psql/tab-complete.c 13 Aug 2004 06:34:55 -0000
***************
*** 633,637 ****
{
static const char *const list_ALTER[] =
! {"DATABASE", "GROUP", "SCHEMA", "TABLE", "TRIGGER", "USER", NULL};
COMPLETE_WITH_LIST(list_ALTER);
--- 633,638 ----
{
static const char *const list_ALTER[] =
! {"DATABASE", "GROUP", "SCHEMA", "TABLE", "TRIGGER", "USER", "INDEX",
! NULL};
COMPLETE_WITH_LIST(list_ALTER);
***************
*** 647,650 ****
--- 648,661 ----
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_ALTERDATABASE[] =
+ {"SET TABLESPACE", "OWNER TO", "RENAME TO", NULL};
+
+ COMPLETE_WITH_LIST(list_ALTERDATABASE);
+ }
+
/* ALTER TRIGGER , add ON */
else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/include/nodes/parsenodes.h,v
retrieving revision 1.265
diff -2 -c -r1.265 parsenodes.h
*** src/include/nodes/parsenodes.h 4 Aug 2004 21:34:24 -0000 1.265
--- src/include/nodes/parsenodes.h 13 Aug 2004 03:50:47 -0000
***************
*** 782,785 ****
--- 782,786 ----
RangeVar *relation; /* table to work on */
List *cmds; /* list of subcommands */
+ ObjectType relkind; /* type of object */
} AlterTableStmt;