*** ./doc/src/sgml/ref/delete.sgml.orig Wed Nov 30 16:47:47 2005 --- ./doc/src/sgml/ref/delete.sgml Wed Nov 30 16:49:12 2005 *************** *** 20,26 **** ! DELETE FROM [ ONLY ] table [ USING usinglist ] [ WHERE condition ] --- 20,26 ---- ! DELETE FROM [ ONLY ] table [ [ AS ] alias ] [ USING usinglist ] [ WHERE condition ] *************** *** 92,97 **** --- 92,110 ---- + alias + + + A substitute name for the target table. When an alias is + provided, it completely hides the actual name of the table. + for example given DELETE foo AS f, the remainder + of the SQL must refer to this table as f not + foo. + + + + + usinglist *** ./doc/src/sgml/ref/update.sgml.orig Wed Nov 30 16:44:11 2005 --- ./doc/src/sgml/ref/update.sgml Fri Dec 2 14:55:31 2005 *************** *** 20,26 **** ! UPDATE [ ONLY ] table SET column = { expression | DEFAULT } [, ...] [ FROM fromlist ] [ WHERE condition ] --- 20,27 ---- ! UPDATE [ ONLY ] table [ [ AS ] alias ] ! SET column = { expression | DEFAULT } [, ...] [ FROM fromlist ] [ WHERE condition ] *************** *** 74,79 **** --- 75,94 ---- + alias + + + A substitute name for the target table. When an alias is + provided, it completely hides the actual name of the table. + for example given UPDATE foo AS f, the remainder + of the SQL must refer to this table as f not + foo. You cannot use the alias for a SET target. + for example SET f.col = 1 is invalid. + + + + + column *** ./src/backend/parser/gram.y.orig Mon Nov 28 13:07:55 2005 --- ./src/backend/parser/gram.y Fri Dec 2 09:16:26 2005 *************** *** 290,295 **** --- 290,296 ---- %type table_ref %type joined_table %type relation_expr + %type update_or_delete_relation_expr %type target_el insert_target_el update_target_el insert_column_item %type Typename SimpleTypename ConstTypename *************** *** 5087,5093 **** * *****************************************************************************/ ! DeleteStmt: DELETE_P FROM relation_expr using_clause where_clause { DeleteStmt *n = makeNode(DeleteStmt); n->relation = $3; --- 5088,5095 ---- * *****************************************************************************/ ! DeleteStmt: DELETE_P FROM update_or_delete_relation_expr ! using_clause where_clause { DeleteStmt *n = makeNode(DeleteStmt); n->relation = $3; *************** *** 5139,5145 **** * *****************************************************************************/ ! UpdateStmt: UPDATE relation_expr SET update_target_list from_clause where_clause --- 5141,5147 ---- * *****************************************************************************/ ! UpdateStmt: UPDATE update_or_delete_relation_expr SET update_target_list from_clause where_clause *************** *** 5817,5822 **** --- 5819,5845 ---- ; + update_or_delete_relation_expr: relation_expr + { + $$ = $1; + } + | relation_expr AS IDENT + { + Alias *alias = makeNode(Alias); + alias->aliasname = $3; + $1->alias = alias; + $$ = $1; + } + | relation_expr IDENT + { + Alias *alias = makeNode(Alias); + alias->aliasname = $2; + $1->alias = alias; + $$ = $1; + } + ; + + func_table: func_expr { $$ = $1; } ; *** ./src/backend/parser/parse_clause.c.orig Mon Nov 28 13:08:31 2005 --- ./src/backend/parser/parse_clause.c Mon Nov 28 13:10:56 2005 *************** *** 160,166 **** * Now build an RTE. */ rte = addRangeTableEntryForRelation(pstate, pstate->p_target_relation, ! NULL, inh, false); pstate->p_target_rangetblentry = rte; /* assume new rte is at end */ --- 160,166 ---- * Now build an RTE. */ rte = addRangeTableEntryForRelation(pstate, pstate->p_target_relation, ! relation->alias, inh, false); pstate->p_target_rangetblentry = rte; /* assume new rte is at end */ *** ./src/test/regress/expected/update.out.orig Fri Dec 2 15:07:55 2005 --- ./src/test/regress/expected/update.out Fri Dec 2 15:10:47 2005 *************** *** 22,25 **** --- 22,41 ---- 10 | (2 rows) + UPDATE update_test as t SET b = 10 where t.a = 10; + SELECT * FROM update_test; + a | b + ----+---- + 10 | 10 + 10 | 10 + (2 rows) + + UPDATE update_test t SET b = t.b + 10 where t.a = 10; + SELECT * FROM update_test; + a | b + ----+---- + 10 | 20 + 10 | 20 + (2 rows) + DROP TABLE update_test; *** ./src/test/regress/sql/update.sql.orig Fri Dec 2 15:05:51 2005 --- ./src/test/regress/sql/update.sql Fri Dec 2 15:09:06 2005 *************** *** 16,19 **** --- 16,27 ---- SELECT * FROM update_test; + UPDATE update_test as t SET b = 10 where t.a = 10; + + SELECT * FROM update_test; + + UPDATE update_test t SET b = t.b + 10 where t.a = 10; + + SELECT * FROM update_test; + DROP TABLE update_test;