aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2006-01-22 05:20:35 +0000
committerNeil Conway <neilc@samurai.com>2006-01-22 05:20:35 +0000
commit1d763d9107eda2db054d0f7edee4c2e9b55dfacf (patch)
tree8493a62bce7056bad829013e2d7abbb89bfa0f2c /src/backend/parser
parent57a84ca48e8901e77583f0c415f288430f5d66af (diff)
downloadpostgresql-1d763d9107eda2db054d0f7edee4c2e9b55dfacf.tar.gz
postgresql-1d763d9107eda2db054d0f7edee4c2e9b55dfacf.zip
Allow an optional alias for the target table to be specified for UPDATE
and DELETE. If specified, the alias must be used instead of the full table name. Also, the alias currently cannot be used in the SET clause of UPDATE. Patch from Atsushi Ogawa, various editorialization by Neil Conway. Along the way, make the rowtypes regression test pass if add_missing_from is enabled, and add a new (skeletal) regression test for DELETE.
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y22
-rw-r--r--src/backend/parser/parse_clause.c4
2 files changed, 21 insertions, 5 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 41b22d811c9..22e20165b96 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.522 2006/01/21 02:16:19 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.523 2006/01/22 05:20:33 neilc Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -291,6 +291,7 @@ static void doNegateFloat(Value *v);
%type <node> table_ref
%type <jexpr> joined_table
%type <range> relation_expr
+%type <range> relation_expr_opt_alias
%type <target> target_el insert_target_el update_target_el insert_column_item
%type <typnam> Typename SimpleTypename ConstTypename
@@ -5148,7 +5149,8 @@ insert_column_item:
*
*****************************************************************************/
-DeleteStmt: DELETE_P FROM relation_expr using_clause where_clause
+DeleteStmt: DELETE_P FROM relation_expr_opt_alias
+ using_clause where_clause
{
DeleteStmt *n = makeNode(DeleteStmt);
n->relation = $3;
@@ -5200,7 +5202,7 @@ opt_nowait: NOWAIT { $$ = TRUE; }
*
*****************************************************************************/
-UpdateStmt: UPDATE relation_expr
+UpdateStmt: UPDATE relation_expr_opt_alias
SET update_target_list
from_clause
where_clause
@@ -5878,6 +5880,20 @@ relation_expr:
;
+relation_expr_opt_alias: relation_expr
+ {
+ $$ = $1;
+ }
+ | relation_expr opt_as IDENT
+ {
+ Alias *alias = makeNode(Alias);
+ alias->aliasname = $3;
+ $1->alias = alias;
+ $$ = $1;
+ }
+ ;
+
+
func_table: func_expr { $$ = $1; }
;
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index aee45f3d205..934802e16ec 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.144 2005/11/22 18:17:16 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.145 2006/01/22 05:20:34 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -160,7 +160,7 @@ setTargetTable(ParseState *pstate, RangeVar *relation,
* Now build an RTE.
*/
rte = addRangeTableEntryForRelation(pstate, pstate->p_target_relation,
- NULL, inh, false);
+ relation->alias, inh, false);
pstate->p_target_rangetblentry = rte;
/* assume new rte is at end */