From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext |
Date: | 2023-06-26 11:20:00 |
Message-ID: | CACJufxEW2e_hgvCWy2Jb=v83FL4AyNQOnTRVxfdj+72EMfJ3aA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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....
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2023-06-26 11:50:55 | Re: function arguments are not PG_FUNCTION_ARGS, how to pass Node *escontext |
Previous Message | Laurenz Albe | 2023-06-26 11:10:50 | Re: Stampede of the JIT compilers |