MCPcopy Create free account
hub / github.com/apache/cloudberry / check_srf_call_placement

Function check_srf_call_placement

src/backend/parser/parse_func.c:2565–2737  ·  view source on GitHub ↗

* check_srf_call_placement * Verify that a set-returning function is called in a valid place, * and throw a nice error if not. * * A side-effect is to set pstate->p_hasTargetSRFs true if appropriate. * * last_srf should be a copy of pstate->p_last_srf from just before we * started transforming the function's arguments. This allows detection * of whether the SRF's arguments contain any S

Source from the content-addressed store, hash-verified

2563 * of whether the SRF's arguments contain any SRFs.
2564 */
2565void
2566check_srf_call_placement(ParseState *pstate, Node *last_srf, int location)
2567{
2568 const char *err;
2569 bool errkind;
2570
2571 /*
2572 * Check to see if the set-returning function is in an invalid place
2573 * within the query. Basically, we don't allow SRFs anywhere except in
2574 * the targetlist (which includes GROUP BY/ORDER BY expressions), VALUES,
2575 * and functions in FROM.
2576 *
2577 * For brevity we support two schemes for reporting an error here: set
2578 * "err" to a custom message, or set "errkind" true if the error context
2579 * is sufficiently identified by what ParseExprKindName will return, *and*
2580 * what it will return is just a SQL keyword. (Otherwise, use a custom
2581 * message to avoid creating translation problems.)
2582 */
2583 err = NULL;
2584 errkind = false;
2585 switch (pstate->p_expr_kind)
2586 {
2587 case EXPR_KIND_NONE:
2588 Assert(false); /* can't happen */
2589 break;
2590 case EXPR_KIND_OTHER:
2591 /* Accept SRF here; caller must throw error if wanted */
2592 break;
2593 case EXPR_KIND_JOIN_ON:
2594 case EXPR_KIND_JOIN_USING:
2595 err = _("set-returning functions are not allowed in JOIN conditions");
2596 break;
2597 case EXPR_KIND_FROM_SUBSELECT:
2598 /* can't get here, but just in case, throw an error */
2599 errkind = true;
2600 break;
2601 case EXPR_KIND_FROM_FUNCTION:
2602 /* okay, but we don't allow nested SRFs here */
2603 /* errmsg is chosen to match transformRangeFunction() */
2604 /* errposition should point to the inner SRF */
2605 if (pstate->p_last_srf != last_srf)
2606 ereport(ERROR,
2607 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2608 errmsg("set-returning functions must appear at top level of FROM"),
2609 parser_errposition(pstate,
2610 exprLocation(pstate->p_last_srf))));
2611 break;
2612 case EXPR_KIND_WHERE:
2613 errkind = true;
2614 break;
2615 case EXPR_KIND_POLICY:
2616 err = _("set-returning functions are not allowed in policy expressions");
2617 break;
2618 case EXPR_KIND_HAVING:
2619 errkind = true;
2620 break;
2621 case EXPR_KIND_FILTER:
2622 errkind = true;

Callers 2

make_opFunction · 0.85
ParseFuncOrColumnFunction · 0.85

Calls 6

parser_errpositionFunction · 0.85
exprLocationFunction · 0.85
ParseExprKindNameFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errmsg_internalFunction · 0.50

Tested by

no test coverage detected