aboutsummaryrefslogtreecommitdiff
path: root/src/tutorial/funcs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2025-01-17 14:37:38 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2025-01-17 14:37:38 -0500
commit86e4efc52b664b60f9494e062bbf0454cabcb61f (patch)
treeaa59b403af8088c07178c3b040fdc484d388d6e1 /src/tutorial/funcs.c
parent43830ecb8a9b6a1bc322298a77a5e0d87c2e83d4 (diff)
downloadpostgresql-86e4efc52b664b60f9494e062bbf0454cabcb61f.tar.gz
postgresql-86e4efc52b664b60f9494e062bbf0454cabcb61f.zip
Add documentation about calling version-1 C functions from C.
This topic wasn't really covered before, so fill in some details. Author: Florents Tselai <florents.tselai@gmail.com> Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/90853055-5BBD-493D-91E5-721677C7C59B@gmail.com
Diffstat (limited to 'src/tutorial/funcs.c')
-rw-r--r--src/tutorial/funcs.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tutorial/funcs.c b/src/tutorial/funcs.c
index f597777a1ff..4a61177567c 100644
--- a/src/tutorial/funcs.c
+++ b/src/tutorial/funcs.c
@@ -11,6 +11,7 @@
#include "postgres.h" /* general Postgres declarations */
#include "executor/executor.h" /* for GetAttributeByName() */
+#include "utils/fmgrprotos.h" /* for text_starts_with() */
#include "utils/geo_decls.h" /* for point type */
PG_MODULE_MAGIC;
@@ -102,6 +103,25 @@ concat_text(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(new_text);
}
+/* A wrapper around starts_with(text, text) */
+
+PG_FUNCTION_INFO_V1(t_starts_with);
+
+Datum
+t_starts_with(PG_FUNCTION_ARGS)
+{
+ text *t1 = PG_GETARG_TEXT_PP(0);
+ text *t2 = PG_GETARG_TEXT_PP(1);
+ Oid collid = PG_GET_COLLATION();
+ bool result;
+
+ result = DatumGetBool(DirectFunctionCall2Coll(text_starts_with,
+ collid,
+ PointerGetDatum(t1),
+ PointerGetDatum(t2)));
+ PG_RETURN_BOOL(result);
+}
+
/* Composite types */
PG_FUNCTION_INFO_V1(c_overpaid);