Revert patch to coerce 'unknown' type parameters in the backend. As Tom
authorHeikki Linnakangas <[email protected]>
Thu, 19 Aug 2010 16:54:51 +0000 (16:54 +0000)
committerHeikki Linnakangas <[email protected]>
Thu, 19 Aug 2010 16:54:51 +0000 (16:54 +0000)
pointed out, it would need a 2nd pass after the whole query is processed to
correctly check that an unknown Param is coerced to the same target type
everywhere. Adding the 2nd pass would add a lot more code, which doesn't
seem worth the risk given that there isn't much of a use case for passing
unknown Params in the first place. The code would work without that check,
but it might be confusing and the behavior would be different from the
varparams case.

Instead, just coerce all unknown params in a PL/pgSQL USING clause to text.
That's simple, and is usually what users expect.

Revert the patch in CVS HEAD and master, and backpatch the new solution to
8.4. Unlike the previous solution, this applies easily to 8.4 too.

src/pl/plpgsql/src/pl_exec.c

index d83756f7cf224300f2f8613138e18acb07f0c1ae..b1ab8299608344572d3d995bb1e07b235a0fa1c1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.244.2.7 2010/08/09 18:50:29 tgl Exp $
+ *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.244.2.8 2010/08/19 16:54:51 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -5428,8 +5428,22 @@ exec_eval_using_params(PLpgSQL_execstate *estate, List *params)
                ppd->nulls[i] = isnull ? 'n' : ' ';
                ppd->freevals[i] = false;
 
+               if (ppd->types[i] == UNKNOWNOID)
+               {
+                       /*
+                        * Treat 'unknown' parameters as text, that's what most people
+                        * would expect. The backend can coerce unknown constants in a
+                        * more intelligent way, but not unknown Params. 
+                        */
+                       ppd->types[i] = TEXTOID;
+                       if (!isnull)
+                       {
+                               ppd->values[i] = CStringGetTextDatum((char *) ppd->values[i]);
+                               ppd->freevals[i] = true;
+                       }
+               }
                /* pass-by-ref non null values must be copied into plpgsql context */
-               if (!isnull)
+               else if (!isnull)
                {
                        int16           typLen;
                        bool            typByVal;