Complain if a function-in-FROM returns a set when it shouldn't.
Throw a "function protocol violation" error if a function in FROM tries to return a set though it wasn't marked proretset. Although such cases work at the moment, it doesn't seem like something we want to guarantee will keep working. Besides, there are other negative consequences of not setting the proretset flag, such as potentially bad plans. No back-patch, since if there is any third-party code violating this expectation, people wouldn't appreciate us breaking it in a minor release. Discussion: https://postgr.es/m/1636062.1615141782@sss.pgh.pa.us
This commit is contained in:
parent
fed10d4eec
commit
d4545dc19b
@ -353,11 +353,21 @@ ExecMakeTableFunctionResult(SetExprState *setexpr,
|
|||||||
*/
|
*/
|
||||||
if (rsinfo.isDone != ExprMultipleResult)
|
if (rsinfo.isDone != ExprMultipleResult)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that set-returning functions were properly declared.
|
||||||
|
* (Note: for historical reasons, we don't complain if a non-SRF
|
||||||
|
* returns ExprEndResult; that's treated as returning NULL.)
|
||||||
|
*/
|
||||||
|
if (!returnsSet)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
|
||||||
|
errmsg("table-function protocol for value-per-call mode was not followed")));
|
||||||
}
|
}
|
||||||
else if (rsinfo.returnMode == SFRM_Materialize)
|
else if (rsinfo.returnMode == SFRM_Materialize)
|
||||||
{
|
{
|
||||||
/* check we're on the same page as the function author */
|
/* check we're on the same page as the function author */
|
||||||
if (!first_time || rsinfo.isDone != ExprSingleResult)
|
if (!first_time || rsinfo.isDone != ExprSingleResult || !returnsSet)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
|
(errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
|
||||||
errmsg("table-function protocol for materialize mode was not followed")));
|
errmsg("table-function protocol for materialize mode was not followed")));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user