From b2ffdfcc33ae6d002395e7c234c2aa3249149015 Mon Sep 17 00:00:00 2001 From: Florents Tselai Date: Wed, 9 Oct 2024 21:46:37 +0300 Subject: [PATCH v2 2/2] Add note on NULL. Update example to use text* --- doc/src/sgml/xfunc.sgml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index eb26120def..ee4330a9cc 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -2397,6 +2397,7 @@ PG_FUNCTION_INFO_V1(funcname); (or its Oid in some cases), and actual arguments should be supplied as Datums. They always return Datum. + Note that neither arguments nor result are allowed to be NULL. @@ -2412,6 +2413,7 @@ PG_FUNCTION_INFO_V1(funcname); you can use DatumGetTextPP(X). If your extension defines additional types, it is usually convenient to define similar macros for these types too. + You can use PointerGetDatum(x) to turn pointers of standard types into Datum @@ -2520,14 +2522,16 @@ PG_FUNCTION_INFO_V1(t_starts_with); Datum t_starts_with(PG_FUNCTION_ARGS) { - Datum t1 = PG_GETARG_DATUM(0); - Datum t2 = PG_GETARG_DATUM(1); - bool bool_res; + text *t1 = PG_GETARG_TEXT_PP(0); + text *t2 = PG_GETARG_TEXT_PP(1); + bool result; - Datum datum_res = DirectFunctionCall2(text_starts_with, t1, t2); - bool_res = DatumGetBool(datum_res); + result = DatumGetBool( + DirectFunctionCall2(text_starts_with, + PointerGetDatum(t1), + PointerGetDatum(t2)); - PG_RETURN_BOOL(bool_res); + PG_RETURN_BOOL(result); } ]]> -- 2.39.5 (Apple Git-154)