Hi,

I noticed that this in make_tuple_from_result_row does conversion error
handling only for the ordinary-column case (ie, errpos.cur_attno is set
for that case, but not for the ctid case).

        /* convert value to internal representation */
        if (i > 0)
        {
            /* ordinary column */
            Assert(i <= tupdesc->natts);
            nulls[i - 1] = (valstr == NULL);
            /* Apply the input function even to nulls, to support domains */
            errpos.cur_attno = i;
            values[i - 1] = InputFunctionCall(&attinmeta->attinfuncs[i - 1],
                                              valstr,
                                              attinmeta->attioparams[i - 1],
                                              attinmeta->atttypmods[i - 1]);
            errpos.cur_attno = 0;
        }
        else if (i == SelfItemPointerAttributeNumber)
        {
            /* ctid --- note we ignore any other system column in result */
            if (valstr != NULL)
            {
                Datum       datum;

                datum = DirectFunctionCall1(tidin, CStringGetDatum(valstr));
                ctid = (ItemPointer) DatumGetPointer(datum);
            }
        }

I think errpos.cur_attno should be set for the ctid case as well.
Attached is a patch for that.

Best regards,
Etsuro Fujita
*** a/contrib/postgres_fdw/postgres_fdw.c
--- b/contrib/postgres_fdw/postgres_fdw.c
***************
*** 3755,3772 **** make_tuple_from_result_row(PGresult *res,
  			valstr = PQgetvalue(res, row, j);
  
  		/* convert value to internal representation */
  		if (i > 0)
  		{
  			/* ordinary column */
  			Assert(i <= tupdesc->natts);
  			nulls[i - 1] = (valstr == NULL);
  			/* Apply the input function even to nulls, to support domains */
- 			errpos.cur_attno = i;
  			values[i - 1] = InputFunctionCall(&attinmeta->attinfuncs[i - 1],
  											  valstr,
  											  attinmeta->attioparams[i - 1],
  											  attinmeta->atttypmods[i - 1]);
- 			errpos.cur_attno = 0;
  		}
  		else if (i == SelfItemPointerAttributeNumber)
  		{
--- 3755,3771 ----
  			valstr = PQgetvalue(res, row, j);
  
  		/* convert value to internal representation */
+ 		errpos.cur_attno = i;
  		if (i > 0)
  		{
  			/* ordinary column */
  			Assert(i <= tupdesc->natts);
  			nulls[i - 1] = (valstr == NULL);
  			/* Apply the input function even to nulls, to support domains */
  			values[i - 1] = InputFunctionCall(&attinmeta->attinfuncs[i - 1],
  											  valstr,
  											  attinmeta->attioparams[i - 1],
  											  attinmeta->atttypmods[i - 1]);
  		}
  		else if (i == SelfItemPointerAttributeNumber)
  		{
***************
*** 3779,3784 **** make_tuple_from_result_row(PGresult *res,
--- 3778,3784 ----
  				ctid = (ItemPointer) DatumGetPointer(datum);
  			}
  		}
+ 		errpos.cur_attno = 0;
  
  		j++;
  	}
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to