*** ./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 ****
  
   <refsynopsisdiv>
  <synopsis>
! DELETE FROM [ ONLY ] <replaceable class="PARAMETER">table</replaceable>
      [ USING <replaceable class="PARAMETER">usinglist</replaceable> ]
      [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
  </synopsis>
--- 20,26 ----
  
   <refsynopsisdiv>
  <synopsis>
! DELETE FROM [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ [ AS ] <replaceable class="parameter">alias</replaceable> ]
      [ USING <replaceable class="PARAMETER">usinglist</replaceable> ]
      [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
  </synopsis>
***************
*** 92,97 ****
--- 92,110 ----
     </varlistentry>
  
     <varlistentry>
+     <term><replaceable class="parameter">alias</replaceable></term>
+     <listitem>
+      <para>
+       A substitute name for the target table. When an alias is
+       provided, it completely hides the actual name of the table.
+       for example given <literal>DELETE foo AS f</>, the remainder
+       of the SQL must refer to this table as <literal>f</> not
+       <literal>foo</>.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
      <term><replaceable class="PARAMETER">usinglist</replaceable></term>
      <listitem>
       <para>
*** ./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 ****
  
   <refsynopsisdiv>
  <synopsis>
! UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replaceable class="PARAMETER">column</replaceable> = { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...]
      [ FROM <replaceable class="PARAMETER">fromlist</replaceable> ]
      [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
  </synopsis>
--- 20,27 ----
  
   <refsynopsisdiv>
  <synopsis>
! UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ [ AS ] <replaceable class="parameter">alias</replaceable> ]
!     SET <replaceable class="PARAMETER">column</replaceable> = { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...]
      [ FROM <replaceable class="PARAMETER">fromlist</replaceable> ]
      [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
  </synopsis>
***************
*** 74,79 ****
--- 75,94 ----
     </varlistentry>
  
     <varlistentry>
+     <term><replaceable class="parameter">alias</replaceable></term>
+     <listitem>
+      <para>
+       A substitute name for the target table. When an alias is
+       provided, it completely hides the actual name of the table.
+       for example given <literal>UPDATE foo AS f</>, the remainder
+       of the SQL must refer to this table as <literal>f</> not
+       <literal>foo</>. You cannot use the alias for a SET target.
+       for example <literal>SET f.col = 1</> is invalid.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
      <term><replaceable class="PARAMETER">column</replaceable></term>
      <listitem>
       <para>
*** ./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 <node>	table_ref
  %type <jexpr>	joined_table
  %type <range>	relation_expr
+ %type <range>	update_or_delete_relation_expr
  %type <target>	target_el insert_target_el update_target_el insert_column_item
  
  %type <typnam>	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;


