• Tom Lane's avatar
    Provide an error cursor for "can't call an SRF here" errors. · e240a65c
    Tom Lane authored
    Since it appears that v10 is going to move the goalposts by some amount
    in terms of where you can and can't invoke set-returning functions,
    arrange for the executor's "set-valued function called in context that
    cannot accept a set" errors to include a syntax position if possible,
    pointing to the specific SRF that can't be called where it's located.
    
    The main bit of infrastructure needed for this is to make the query source
    text accessible in the executor; but it turns out that commit 4c728f38
    already did that.  We just need a new function executor_errposition()
    modeled on parser_errposition(), and we're ready to rock.
    
    While experimenting with this, I noted that the error position wasn't
    properly reported if it occurred in a plpgsql FOR-over-query loop,
    which turned out to be because SPI_cursor_open_internal wasn't providing
    an error context callback during PortalStart.  Fix that.
    
    There's a whole lot more that could be done with this infrastructure
    now that it's there, but this is not the right time in the development
    cycle for that sort of work.  Hence, resist the temptation to plaster
    executor_errposition() calls everywhere ... for the moment.
    
    Discussion: https://postgr.es/m/5263.1492471571@sss.pgh.pa.us
    e240a65c
execExpr.c 77.8 KB