​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext

Поиск
Список
Период
Сортировка
От jian he
Тема ​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext
Дата
Msg-id CACJufxEW2e_hgvCWy2Jb=v83FL4AyNQOnTRVxfdj+72EMfJ3aA@mail.gmail.com
обсуждение исходный текст
Ответы Re: ​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
hi. simple question....

The following one works.
------------------------------------------------------------
Datum
test_direct_inputcall(PG_FUNCTION_ARGS)
{
    char    *token  = PG_GETARG_CSTRING(0);
    Datum   numd;
    if (!DirectInputFunctionCallSafe(numeric_in, token,
                                        InvalidOid, -1,
                                        fcinfo->context,
                                        &numd))
    {
        elog(INFO,"convert to cstring failed");
        PG_RETURN_BOOL(false);
    }
    elog(INFO,"%s",DatumGetCString(DirectFunctionCall1(numeric_out,numd)));
    PG_RETURN_BOOL(true);
}
------------------------------------------------------------
--the following one does not work. will print out something is wrong

Datum
test_direct_inputcall(PG_FUNCTION_ARGS)
{
    char    *token  = PG_GETARG_CSTRING(0);
    Datum   numd;
    numd    = return_numeric_datum(token);
    elog(INFO,"%s",DatumGetCString(DirectFunctionCall1(numeric_out,numd)));
    PG_RETURN_BOOL(true);
}

static
Datum return_numeric_datum(char *token)
{
    Datum   numd;
    Node    *escontext;

    if (!DirectInputFunctionCallSafe(numeric_in, token,
                                    InvalidOid, -1,
                                    escontext,
                                    &numd));
        elog(INFO,"something is wrong");
    return numd;
}
------------------------------------------------------------
I wonder how to make it return_numeric_datum works in functions that
arguments are not PG_FUNCTION_ARGS.

To make it work, I need to understand the Node *context, which is kind
of a vague idea for me.
In the top level function (input as PG_FUNCTION_ARGS) the Node
*context can be used to print out errors and back to normal state, I
kind of get it.

I really appreciate someone showing a minimal, reproducible example
based on return_numeric_datum....



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

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: Stampede of the JIT compilers
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: ​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext