diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-04-19 04:17:11 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-04-19 04:17:11 +0000 |
commit | a58843b49afdc15c3e319072916a4d9390cf70b1 (patch) | |
tree | 472b1f7033e0eb2d7de6f55844346cde0f518e71 /src/backend/parser/parse_expr.c | |
parent | 4438b70b945f71ac35b5031d3f07e7e973449247 (diff) | |
download | postgresql-a58843b49afdc15c3e319072916a4d9390cf70b1.tar.gz postgresql-a58843b49afdc15c3e319072916a4d9390cf70b1.zip |
Fix problems seen when result of a subselect was used in an
expression context (ie, not at the top level of a WHERE clause). Examples
like this one work now:
SELECT name, value FROM t1 as touter WHERE
(value/(SELECT AVG(value) FROM t1 WHERE name = touter.name)) > 0.75;
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r-- | src/backend/parser/parse_expr.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index d23d7214a34..f18fbd46eed 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.41 1999/04/18 17:35:51 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.42 1999/04/19 04:17:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -312,14 +312,6 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) op_expr = make_op(op, lexpr, tent->expr); - /* - * HACK! Second IF is more valid but currently we - * don't support EXPR subqueries inside - * expressions generally, only in WHERE clauses. - * After fixing this, first IF must be removed. - */ - if (op_expr->typeOid != BOOLOID) - elog(ERROR, "parser: '%s' must return 'bool' to be used with subquery", op); if (op_expr->typeOid != BOOLOID && sublink->subLinkType != EXPR_SUBLINK) elog(ERROR, "parser: '%s' must return 'bool' to be used with quantified predicate subquery", op); @@ -598,7 +590,20 @@ exprType(Node *expr) type = ((Param *) expr)->paramtype; break; case T_SubLink: - type = BOOLOID; + { + SubLink *sublink = (SubLink *) expr; + if (sublink->subLinkType == EXPR_SUBLINK) + { + /* return the result type of the combining operator */ + Expr *op_expr = (Expr *) lfirst(sublink->oper); + type = op_expr->typeOid; + } + else + { + /* for all other sublink types, result is boolean */ + type = BOOLOID; + } + } break; case T_CaseExpr: type = ((CaseExpr *) expr)->casetype; |