v2-0002-Add-note-on-NULL.-Update-example-to-use-text.patch
application/octet-stream
Filename: v2-0002-Add-note-on-NULL.-Update-example-to-use-text.patch
Type: application/octet-stream
Part: 1
Patch
Format: format-patch
Series: patch v2-0002
Subject: Add note on NULL. Update example to use text*
| File | + | − |
|---|---|---|
| doc/src/sgml/xfunc.sgml | 10 | 6 |
From b2ffdfcc33ae6d002395e7c234c2aa3249149015 Mon Sep 17 00:00:00 2001
From: Florents Tselai <florents.tselai@gmail.com>
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 <literal>Oid</literal> in some cases),
and actual arguments should be supplied as <literal>Datum</literal>s.
They always return <literal>Datum</literal>.
+ Note that neither arguments nor result are allowed to be NULL.
</para>
<para>
@@ -2412,6 +2413,7 @@ PG_FUNCTION_INFO_V1(funcname);
you can use <function>DatumGetTextPP(X)</function>.
If your extension defines additional types,
it is usually convenient to define similar macros for these types too.
+ You can use <function>PointerGetDatum(x)</function> to turn pointers of standard types into <literal>Datum</literal>
</para>
<para>
@@ -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);
}
]]>
</programlisting>
--
2.39.5 (Apple Git-154)