From 73f5b0847b1edd93efdab9a8aad4499ae37d3cc5 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 11 Mar 2000 06:19:00 +0000 Subject: [PATCH] exec_simple_check_plan() must not allow a plan having initPlans or subPlans to be considered 'simple'. This fixes reported problem with 'return exists (select 1 from foo);' in plpgsql function. --- src/pl/plpgsql/src/pl_exec.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index d58c9893f7..dfb4d25230 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.18 2000/02/07 03:39:13 inoue Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.19 2000/03/11 06:19:00 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -2510,30 +2510,35 @@ exec_simple_check_plan(PLpgSQL_expr * expr) if (plan == NULL) /* utility statement produces this */ return; - if (nodeTag(plan) != T_Result) + if (! IsA(plan, Result)) return; /* ---------- - * 3. The plan must have a single attribute as result + * 3. Can't have any subplan or qual clause, either * ---------- */ - if (length(plan->targetlist) != 1) + if (plan->lefttree != NULL || + plan->righttree != NULL || + plan->initPlan != NULL || + plan->subPlan != NULL || + plan->qual != NULL || + ((Result *) plan)->resconstantqual != NULL) return; /* ---------- - * 4. Don't know if all these can break us, so let SPI handle - * those plans + * 4. The plan must have a single attribute as result * ---------- */ - if (plan->qual != NULL || plan->lefttree != NULL || plan->righttree != NULL) + if (length(plan->targetlist) != 1) return; + tle = (TargetEntry *) lfirst(plan->targetlist); + /* ---------- * 5. Check that all the nodes in the expression are one of * Expr, Param or Const. * ---------- */ - tle = (TargetEntry *) lfirst(plan->targetlist); if (!exec_simple_check_node(tle->expr)) return; @@ -2563,8 +2568,6 @@ exec_simple_check_plan(PLpgSQL_expr * expr) default: expr->plan_simple_type = InvalidOid; } - - return; } -- 2.11.0