Supporting $n parameters in new syntax

Поиск
Список
Период
Сортировка
От Paul A Jungwirth
Тема Supporting $n parameters in new syntax
Дата
Msg-id CA+renyU5dpNqmvTKYQrg=G6fQA3Fp5LQhyAg_d-w_YqkRCoyMA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Supporting $n parameters in new syntax  (Paul A Jungwirth <pj@illuminatedcomputing.com>)
Список pgsql-hackers
Hello hackers,

I'm wrapping up a patch that adds SQL:2011 FOR PORTION OF syntax and
then uses it to implement CASCADE in temporal foreign keys. The FKs
are implemented as triggers, like ordinary FKs, and the trigger
function makes a call through SPI that does `UPDATE %s FOR PORTION OF
%s FROM $%d TO $%d`. But I suspect I'm missing something in the
analyze/rewriting phase, because I get this error:

ERROR:  no value found for parameter 1

That's coming from ExecEvalParamExtern in executor/execExprInterp.c.

If I hardcode some dates instead, the query works (even if I use the
same parameters elsewhere). Does anyone have any hints what I may be
missing? Any suggestions for some other syntax to consult as an
example (e.g. ON CONFLICT DO UPDATE)?

In gram.y I parse the phrase like this:

FOR PORTION OF ColId FROM a_expr TO a_expr

Then in the analysis phase I do this:

    /*
     * Build a range from the FROM ... TO .... bounds.
     * This should give a constant result, so we accept functions like NOW()
     * but not column references, subqueries, etc.
     *
     * It also permits MINVALUE and MAXVALUE like declarative partitions.
     */
    Node *target_start = transformForPortionOfBound(forPortionOf->target_start);
    Node *target_end   = transformForPortionOfBound(forPortionOf->target_end);
    FuncCall *fc = makeFuncCall(SystemFuncName(range_type_name),
                                list_make2(target_start, target_end),
                                COERCE_EXPLICIT_CALL,
                                forPortionOf->range_name_location);
    result->targetRange = transformExpr(pstate, (Node *) fc,
EXPR_KIND_UPDATE_PORTION);

(transformForPortionOfBound just handles MIN/MAXVALUE, and for
targetRange I feed the bounds into a range type constructor to use
later.)

I was hoping that transformExpr would do everything I need re
identifying parameters, but maybe there is something else in a later
phase?

Thanks,
Paul



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pgbench test failing on 14beta1 on Debian/i386
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: PG 14 release notes, first draft