aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-02-15 22:17:06 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-02-15 22:17:06 +0000
commite67867b26cf052e166b39c6457ee04861cb81ead (patch)
treedafa8a47410c9f23565fe3df13368d06640bb060 /src/backend
parentcc80f0a340cdeba7716c5e128346481b82cc6949 (diff)
downloadpostgresql-e67867b26cf052e166b39c6457ee04861cb81ead.tar.gz
postgresql-e67867b26cf052e166b39c6457ee04861cb81ead.zip
Allow AS to be omitted when specifying an output column name in SELECT
(or RETURNING), but only when the output name is not any SQL keyword. This seems as close as we can get to the standard's syntax without a great deal of thrashing. Original patch by Hiroshi Saito, amended by me.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/parser/gram.y20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 2b992fab4a7..4688bc79778 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.606 2008/02/07 21:07:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.607 2008/02/15 22:17:06 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -477,6 +477,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
%nonassoc BETWEEN
%nonassoc IN_P
%left POSTFIXOP /* dummy for postfix Op rules */
+%nonassoc IDENT /* to support target_el without AS */
%left Op OPERATOR /* multi-character ops and user-defined operators */
%nonassoc NOTNULL
%nonassoc ISNULL
@@ -8705,7 +8706,6 @@ target_list:
| target_list ',' target_el { $$ = lappend($1, $3); }
;
-/* AS is not optional because shift/red conflict with unary ops */
target_el: a_expr AS ColLabel
{
$$ = makeNode(ResTarget);
@@ -8714,6 +8714,22 @@ target_el: a_expr AS ColLabel
$$->val = (Node *)$1;
$$->location = @1;
}
+ /*
+ * We support omitting AS only for column labels that aren't
+ * any known keyword. There is an ambiguity against postfix
+ * operators: is "a ! b" an infix expression, or a postfix
+ * expression and a column label? We prefer to resolve this
+ * as an infix expression, which we accomplish by assigning
+ * IDENT a precedence higher than POSTFIXOP.
+ */
+ | a_expr IDENT
+ {
+ $$ = makeNode(ResTarget);
+ $$->name = $2;
+ $$->indirection = NIL;
+ $$->val = (Node *)$1;
+ $$->location = @1;
+ }
| a_expr
{
$$ = makeNode(ResTarget);