Alter ALTER TABLE statement ...

From: Oliver Teuber <teuber(at)core(dot)devicen(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Alter ALTER TABLE statement ...
Date: 2002-06-24 19:48:05
Message-ID: 20020624214805.A13798@core.devicen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi

i want to alter the ALTER TABLE xxx ADD statement to allow
the following syntax:

ALTER TABLE [ ONLY ] table
ADD [ COLUMN ] ( column type [ column_constraint ] [, column type [ column_constraint ]] )

just to add one or more columns to a table with one alter table statement.

i know .. its easier to use multiple alter table statements
but the database client application uses this syntax and
i cant change the client application.

here is my first "small" patch to v7.2.1. i have some
problems whith the concept of the Nodes.

maybe someone could give me an hint how i could
implement this.

yours, oliver teuber

diff -cr postgresql-7.2.1/src/backend/parser/analyze.c postgresql-7.2.1-oli/src/backend/parser/analyze.c
*** postgresql-7.2.1/src/backend/parser/analyze.c Wed Feb 27 00:48:43 2002
--- postgresql-7.2.1-oli/src/backend/parser/analyze.c Mon Jun 24 21:03:41 2002
***************
*** 2519,2524 ****
--- 2519,2532 ----
*/
switch (stmt->subtype)
{
+ case 'M':
+
+
+ /* ... some hints please ;) */
+
+
+ break;
+
case 'A':
cxt.stmtType = "ALTER TABLE";
cxt.relname = stmt->relname;
diff -cr postgresql-7.2.1/src/backend/parser/gram.y postgresql-7.2.1-oli/src/backend/parser/gram.y
*** postgresql-7.2.1/src/backend/parser/gram.y Sat Mar 9 18:41:04 2002
--- postgresql-7.2.1-oli/src/backend/parser/gram.y Mon Jun 24 20:42:01 2002
***************
*** 1070,1075 ****
--- 1070,1085 ----
n->def = $6;
$$ = (Node *)n;
}
+ /* ALTER TABLE <relation> ADD [COLUMN] <coldef> */
+ | ALTER TABLE relation_expr ADD opt_column '(' OptTableElementList ')'
+ {
+ AlterTableStmt *n = makeNode(AlterTableStmt);
+ n->subtype = 'M';
+ n->relname = $3->relname;
+ n->inhOpt = $3->inhOpt;
+ n->ldef = $7;
+ $$ = (Node *)n;
+ }
/* ALTER TABLE <relation> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
| ALTER TABLE relation_expr ALTER opt_column ColId alter_column_default
{
diff -cr postgresql-7.2.1/src/include/nodes/parsenodes.h postgresql-7.2.1-oli/src/include/nodes/parsenodes.h
*** postgresql-7.2.1/src/include/nodes/parsenodes.h Wed Feb 27 00:48:46 2002
--- postgresql-7.2.1-oli/src/include/nodes/parsenodes.h Mon Jun 24 20:41:02 2002
***************
*** 121,126 ****
--- 121,127 ----
NodeTag type;
char subtype; /*------------
* A = add column
+ * M = add columns
* T = alter column default
* S = alter column statistics
* D = drop column
***************
*** 135,140 ****
--- 136,142 ----
char *name; /* column or constraint name to act on, or
* new owner */
Node *def; /* definition of new column or constraint */
+ List *ldef;
int behavior; /* CASCADE or RESTRICT drop behavior */
} AlterTableStmt;

Browse pgsql-hackers by date

  From Date Subject
Next Message Nigel J. Andrews 2002-06-24 19:55:06 Re: pg_restore: [archiver] input file does not appear to
Previous Message cbbrowne 2002-06-24 18:03:48 Re: A fairly obvious optimization?