​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext - Mailing list pgsql-hackers

From jian he
Subject ​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext
Date
Msg-id CACJufxEW2e_hgvCWy2Jb=v83FL4AyNQOnTRVxfdj+72EMfJ3aA@mail.gmail.com
Whole thread Raw
Responses Re: ​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext
List 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 by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Stampede of the JIT compilers
Next
From: Andrew Dunstan
Date:
Subject: Re: ​function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext