*/
exec_run_select(estate, stmt->query, 0);
n = SPI_processed;
+ tuptab = SPI_tuptable;
+ SPI_tuptable = NULL;
/*
* If the query didn't return any row, set the target to NULL and
/*
* Now do the loop
*/
- tuptab = SPI_tuptable;
- SPI_tuptable = NULL;
-
for (i = 0; i < n; i++)
{
*/
exec_run_select(estate, stmt->query, 1);
n = SPI_processed;
+ tuptab = SPI_tuptable;
+ SPI_tuptable = NULL;
/*
* If the query didn't return any row, set the target to NULL and
/*
* Put the result into the target and set found to true
*/
- tuptab = SPI_tuptable;
- SPI_tuptable = NULL;
-
exec_move_row(estate, rec, row, tuptab->vals[0], tuptab->tupdesc);
exec_set_found(estate, true);
pfree(querystr);
n = SPI_processed;
+ tuptab = SPI_tuptable;
+ SPI_tuptable = NULL;
/*
* If the query didn't return any row, set the target to NULL and
/*
* Now do the loop
*/
- tuptab = SPI_tuptable;
- SPI_tuptable = NULL;
-
for (i = 0; i < n; i++)
{
* Check that the expression returned one single Datum
*/
if (SPI_processed > 1)
- elog(ERROR, "query \"%s\" didn't return a single value", expr->query);
+ elog(ERROR, "query \"%s\" returned more than one row", expr->query);
if (SPI_tuptable->tupdesc->natts != 1)
- elog(ERROR, "query \"%s\" didn't return a single value", expr->query);
+ elog(ERROR, "query \"%s\" returned more than one column", expr->query);
/*
* Return the result and its type
if (i < t_natts)
{
value = SPI_getbinval(tup, tupdesc, i + 1, &isnull);
+ valtype = SPI_gettypeid(tupdesc, i + 1);
}
else
{
value = (Datum) 0;
isnull = true;
+ valtype = InvalidOid;
}
- /* tupdesc should have entries for all columns I expect... */
- valtype = SPI_gettypeid(tupdesc, i + 1);
exec_assign_value(estate, estate->datums[row->varnos[i]],
value, valtype, &isnull);