aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-01-30 14:16:16 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-01-30 14:17:48 -0500
commit670a6c7a228aea1f31fb96f6bfa69969962e133e (patch)
treeaaa9aae11fb349973baf71a1cd997cdab8094378 /src/backend/parser
parent574f7643214d8381a03083ffbb08ecceec44d6b2 (diff)
downloadpostgresql-670a6c7a228aea1f31fb96f6bfa69969962e133e.tar.gz
postgresql-670a6c7a228aea1f31fb96f6bfa69969962e133e.zip
Fix grammar for subscripting or field selection from a sub-SELECT result.
Such cases should work, but the grammar failed to accept them because of our ancient precedence hacks to convince bison that extra parentheses around a sub-SELECT in an expression are unambiguous. (Formally, they *are* ambiguous, but we don't especially care whether they're treated as part of the sub-SELECT or part of the expression. Bison cares, though.) Fix by adding a redundant-looking production for this case. This is a fine example of why fixing shift/reduce conflicts via precedence declarations is more dangerous than it looks: you can easily cause the parser to reject cases that should work. This has been wrong since commit 3db4056e22b0c6b2adc92543baf8408d2894fe91 or maybe before, and apparently some people have been working around it by inserting no-op casts. That method introduces a dump/reload hazard, as illustrated in bug #7838 from Jan Mate. Hence, back-patch to all active branches.
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 828e11058e9..a2078ec95ef 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -10839,6 +10839,29 @@ c_expr: columnref { $$ = $1; }
n->location = @1;
$$ = (Node *)n;
}
+ | select_with_parens indirection
+ {
+ /*
+ * Because the select_with_parens nonterminal is designed
+ * to "eat" as many levels of parens as possible, the
+ * '(' a_expr ')' opt_indirection production above will
+ * fail to match a sub-SELECT with indirection decoration;
+ * the sub-SELECT won't be regarded as an a_expr as long
+ * as there are parens around it. To support applying
+ * subscripting or field selection to a sub-SELECT result,
+ * we need this redundant-looking production.
+ */
+ SubLink *n = makeNode(SubLink);
+ A_Indirection *a = makeNode(A_Indirection);
+ n->subLinkType = EXPR_SUBLINK;
+ n->testexpr = NULL;
+ n->operName = NIL;
+ n->subselect = $1;
+ n->location = @1;
+ a->arg = (Node *)n;
+ a->indirection = check_indirection($2, yyscanner);
+ $$ = (Node *)a;
+ }
| EXISTS select_with_parens
{
SubLink *n = makeNode(SubLink);