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....


Reply via email to