diff options
| author | Tom Lane | 2004-05-05 04:48:48 +0000 |
|---|---|---|
| committer | Tom Lane | 2004-05-05 04:48:48 +0000 |
| commit | 077db40fa1f3ef93a60d995cc5b2666474f81302 (patch) | |
| tree | 911e14b79a368b10ad9fc267fa69f299e86b15f9 /src/include/nodes | |
| parent | 3e3cb0a14a608bb058407b6349c3c9e2d09e13b8 (diff) | |
ALTER TABLE rewrite. New cool stuff:
* ALTER ... ADD COLUMN with defaults and NOT NULL constraints works per SQL
spec. A default is implemented by rewriting the table with the new value
stored in each row.
* ALTER COLUMN TYPE. You can change a column's datatype to anything you
want, so long as you can specify how to convert the old value. Rewrites
the table. (Possible future improvement: optimize no-op conversions such
as varchar(N) to varchar(N+1).)
* Multiple ALTER actions in a single ALTER TABLE command. You can perform
any number of column additions, type changes, and constraint additions with
only one pass over the table contents.
Basic documentation provided in ALTER TABLE ref page, but some more docs
work is needed.
Original patch from Rod Taylor, additional work from Tom Lane.
Diffstat (limited to 'src/include/nodes')
| -rw-r--r-- | src/include/nodes/nodes.h | 3 | ||||
| -rw-r--r-- | src/include/nodes/parsenodes.h | 71 |
2 files changed, 46 insertions, 28 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index d5d4f0832a7..a776607ec66 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.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/nodes.h,v 1.152 2004/04/01 21:28:46 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.153 2004/05/05 04:48:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -200,6 +200,7 @@ typedef enum NodeTag T_UpdateStmt, T_SelectStmt, T_AlterTableStmt, + T_AlterTableCmd, T_AlterDomainStmt, T_SetOperationStmt, T_GrantStmt, diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index ab505939bc3..8eceb6e59cb 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.254 2004/03/11 01:47:41 ishii Exp $ + * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.255 2004/05/05 04:48:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -762,44 +762,58 @@ typedef enum DropBehavior /* ---------------------- * Alter Table - * - * The fields are used in different ways by the different variants of - * this command. * ---------------------- */ typedef struct AlterTableStmt { NodeTag type; - char subtype; /*------------ - * A = add column - * T = alter column default - * N = alter column drop not null - * n = alter column set not null - * S = alter column statistics - * M = alter column storage - * D = drop column - * C = add constraint - * c = pre-processed add constraint - * (local in parser/analyze.c) - * X = drop constraint - * E = create toast table - * U = change owner - * L = CLUSTER ON - * o = DROP OIDS - *------------ - */ RangeVar *relation; /* table to work on */ + List *cmds; /* list of subcommands */ +} AlterTableStmt; + +typedef enum AlterTableType +{ + AT_AddColumn, /* add column */ + AT_ColumnDefault, /* alter column default */ + AT_DropNotNull, /* alter column drop not null */ + AT_SetNotNull, /* alter column set not null */ + AT_SetStatistics, /* alter column statistics */ + AT_SetStorage, /* alter column storage */ + AT_DropColumn, /* drop column */ + AT_DropColumnRecurse, /* internal to commands/tablecmds.c */ + AT_AddIndex, /* add index */ + AT_ReAddIndex, /* internal to commands/tablecmds.c */ + AT_AddConstraint, /* add constraint */ + AT_ProcessedConstraint, /* pre-processed add constraint + * (local in parser/analyze.c) */ + AT_DropConstraint, /* drop constraint */ + AT_DropConstraintQuietly, /* drop constraint, no error/warning + * (local in commands/tablecmds.c) */ + AT_AlterColumnType, /* alter column type */ + AT_ToastTable, /* create toast table */ + AT_ChangeOwner, /* change owner */ + AT_ClusterOn, /* CLUSTER ON */ + AT_DropOids /* SET WITHOUT OIDS */ +} AlterTableType; + +typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */ +{ + NodeTag type; + AlterTableType subtype; /* Type of table alteration to apply */ char *name; /* column or constraint name to act on, or * new owner */ - Node *def; /* definition of new column or constraint */ + Node *def; /* definition of new column, column type, + * index, or constraint */ + Node *transform; /* transformation expr for ALTER TYPE */ DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ -} AlterTableStmt; +} AlterTableCmd; + /* ---------------------- * Alter Domain * * The fields are used in different ways by the different variants of - * this command. Subtypes should match AlterTable subtypes where possible. + * this command. * ---------------------- */ typedef struct AlterDomainStmt @@ -814,7 +828,7 @@ typedef struct AlterDomainStmt * U = change owner *------------ */ - List *typename; /* table to work on */ + List *typename; /* domain to work on */ char *name; /* column or constraint name to act on, or * new owner */ Node *def; /* definition of default or constraint */ @@ -922,6 +936,8 @@ typedef struct CreateStmt * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt * * XXX probably these ought to be unified with FkConstraints at some point? + * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though + * the parser does not generate it. * * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK) * we may have the expression in either "raw" form (an untransformed @@ -944,6 +960,7 @@ typedef enum ConstrType /* types of constraints */ CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK, + CONSTR_FOREIGN, CONSTR_PRIMARY, CONSTR_UNIQUE, CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ @@ -1291,7 +1308,7 @@ typedef struct FetchStmt typedef struct IndexStmt { NodeTag type; - char *idxname; /* name of the index */ + char *idxname; /* name of new index, or NULL for default */ RangeVar *relation; /* relation to build index on */ char *accessMethod; /* name of access method (eg. btree) */ List *indexParams; /* a list of IndexElem */ |
