aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/gram.y58
-rw-r--r--src/backend/tcop/utility.c21
-rw-r--r--src/bin/psql/tab-complete.c15
-rw-r--r--src/include/nodes/parsenodes.h3
4 files changed, 78 insertions, 19 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e8bc3cf5ade..5240a69dd23 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 <node> alter_column_default opclass_item alter_using
%type <ival> add_drop
-%type <node> alter_table_cmd
-%type <list> alter_table_cmds
+%type <node> alter_table_cmd alter_rel_cmd
+%type <list> alter_table_cmds alter_rel_cmds
%type <dbehavior> 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 <name> OWNER TO UserId */
- | OWNER TO UserId
- {
- AlterTableCmd *n = makeNode(AlterTableCmd);
- n->subtype = AT_ChangeOwner;
- n->name = $3;
- $$ = (Node *)n;
- }
/* ALTER TABLE <name> CLUSTER ON <indexname> */
| CLUSTER ON name
{
@@ -1286,7 +1287,27 @@ alter_table_cmd:
n->name = NULL;
$$ = (Node *)n;
}
- /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
+ | 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 ] <name> OWNER TO UserId */
+ OWNER TO UserId
+ {
+ AlterTableCmd *n = makeNode(AlterTableCmd);
+ n->subtype = AT_ChangeOwner;
+ n->name = $3;
+ $$ = (Node *)n;
+ }
+ /* ALTER [ TABLE | INDEX ] <name> SET TABLESPACE <tablespacename> */
| 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 0fff253a61c..b8c853c0f34 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 130fcd33f4b..1b036be8427 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 <name> */
+ 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 <name>, 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 aff28bea08f..862b2572d91 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