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;
  



Mon, 24 Jun 2002 21:48:05 +0200
Oliver Teuber <teuber@core.devicen.de>
Alter ALTER TABLE statement ...