--- /dev/null
+
+
+
+
+ ALTER INDEX
+ SQL - Language Statements
+
+
+
+ ALTER INDEX
+ change the definition of an 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.
+
+
+
+
+
*
*
* 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
%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
/*****************************************************************************
*
- * ALTER TABLE variations
+ * ALTER [ TABLE | INDEX ] variations
*
*****************************************************************************/
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;
}
;
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
{
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);
| /* EMPTY */ { $$ = NULL; }
;
+
+
/*****************************************************************************
*
* QUERY :
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);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
case OBJECT_GROUP:
tag = "ALTER GROUP";
break;
+ case OBJECT_INDEX:
+ tag = "ALTER INDEX";
+ break;
case OBJECT_LANGUAGE:
tag = "ALTER LANGUAGE";
break;
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;
*
* 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 $
*/
/*----------------------------------------------------------------------
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);
}
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)
* 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 $
*
*-------------------------------------------------------------------------
*/
NodeTag type;
RangeVar *relation; /* table to work on */
List *cmds; /* list of subcommands */
+ ObjectType relkind; /* type of object */
} AlterTableStmt;
typedef enum AlterTableType