Re: variable not found in subplan target list? + test case - Mailing list pgsql-bugs

From Tom Lane
Subject Re: variable not found in subplan target list? + test case
Date
Msg-id 9637.1069804974@sss.pgh.pa.us
Whole thread Raw
In response to Re: variable not found in subplan target list? + test case  (Klint Gore <kg@kgb.une.edu.au>)
Responses Re: variable not found in subplan target list? + test case  (Klint Gore <kg@kgb.une.edu.au>)
List pgsql-bugs
Klint Gore <kg@kgb.une.edu.au> writes:
>> Can you send a test case with table and view definitions, it's hard to
>> generate one from just the information above.

> ok.  the last select generates the error.

Hoo, that was a fun one.  Here's the patch.

            regards, tom lane

*** src/backend/optimizer/plan/subselect.c.orig    Tue Nov 25 16:00:54 2003
--- src/backend/optimizer/plan/subselect.c    Tue Nov 25 18:25:32 2003
***************
*** 118,123 ****
--- 118,128 ----
       * well, I believe that this sort of aliasing will cause no trouble.
       * The correct field should get stored into the Param slot at
       * execution in each part of the tree.
+      *
+      * We also need to demand a match on vartypmod.  This does not matter
+      * for the Param itself, since those are not typmod-dependent, but it
+      * does matter when make_subplan() instantiates a modified copy of the
+      * Var for a subplan's args list.
       */
      i = 0;
      foreach(ppl, PlannerParamList)
***************
*** 129,135 ****

              if (pvar->varno == var->varno &&
                  pvar->varattno == var->varattno &&
!                 pvar->vartype == var->vartype)
                  break;
          }
          i++;
--- 134,141 ----

              if (pvar->varno == var->varno &&
                  pvar->varattno == var->varattno &&
!                 pvar->vartype == var->vartype &&
!                 pvar->vartypmod == var->vartypmod)
                  break;
          }
          i++;

pgsql-bugs by date:

Previous
From: "Arthur Ward"
Date:
Subject: Re: 7.4RC2 PANIC: insufficient room in FSM
Next
From: Tom Lane
Date:
Subject: Re: SELECT with MANY tables