Increased error verbosity when querying row-returning functions - Mailing list pgsql-patches

From Brendan Jurd
Subject Increased error verbosity when querying row-returning functions
Date
Msg-id 41E451DE.5070804@blakjak.sytes.net
Whole thread Raw
Responses Re: Increased error verbosity when querying row-returning functions
List pgsql-patches
This patch to src/backend/executor/nodeFunctionscan.c is intended to
make life a little easier for people using row-returning functions, by
increasing the level of detail in the error messages thrown when
tupledesc_match fails.

Cheers

BJ


Index: src/backend/executor/nodeFunctionscan.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v
retrieving revision 1.29
diff -c -r1.29 nodeFunctionscan.c
*** src/backend/executor/nodeFunctionscan.c    31 Dec 2004 21:59:45 -0000    1.29
--- src/backend/executor/nodeFunctionscan.c    11 Jan 2005 22:17:16 -0000
***************
*** 87,96 ****
           * need to do this for functions returning RECORD, but might as
           * well do it always.
           */
!         if (funcTupdesc && !tupledesc_match(node->tupdesc, funcTupdesc))
!             ereport(ERROR,
!                     (errcode(ERRCODE_DATATYPE_MISMATCH),
!                      errmsg("query-specified return row and actual function return row do not match")));
      }

      /*
--- 87,94 ----
           * need to do this for functions returning RECORD, but might as
           * well do it always.
           */
!         if( funcTupdesc )
!             tupledesc_match(node->tupdesc, funcTupdesc);
      }

      /*
***************
*** 363,369 ****
--- 361,373 ----
      int            i;

      if (dst_tupdesc->natts != src_tupdesc->natts)
+     {
+         ereport(ERROR,
+             (errcode(ERRCODE_DATATYPE_MISMATCH),
+              errmsg("function return row and query-specified return row do not match"),
+              errdetail("function-returned row contains %d attributes, but query expects %d.", src_tupdesc->natts,
dst_tupdesc->natts)));
          return false;
+     }

      for (i = 0; i < dst_tupdesc->natts; i++)
      {
***************
*** 373,382 ****
--- 377,401 ----
          if (dattr->atttypid == sattr->atttypid)
              continue;            /* no worries */
          if (!dattr->attisdropped)
+         {
+             ereport(ERROR,
+                 (errcode(ERRCODE_DATATYPE_MISMATCH),
+                  errmsg("function return row and query-specified return row do not match"),
+                  errdetail("function returned type %s at ordinal position %d, but query expects %s.",
+                      format_type_be(sattr->atttypid),
+                      i+1,
+                      format_type_be(dattr->atttypid))));
              return false;
+         }
          if (dattr->attlen != sattr->attlen ||
              dattr->attalign != sattr->attalign)
+         {
+             ereport(ERROR,
+                 (errcode(ERRCODE_DATATYPE_MISMATCH),
+                  errmsg("function return row and query-specified return row do not match"),
+                  errdetail("physical storage mismatch on dropped attribute at ordinal position %d.", i+1)));
              return false;
+         }
      }

      return true;

pgsql-patches by date:

Previous
From: Mark Kirkwood
Date:
Subject: Re: Another Plpgsql trigger example - summary table
Next
From: Alvaro Herrera
Date:
Subject: Re: Increased error verbosity when querying row-returning functions