diff options
author | Michael Paquier <michael@paquier.xyz> | 2020-08-18 11:10:50 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2020-08-18 11:10:50 +0900 |
commit | adbe62d04b360bbd408d97e447932d8078485972 (patch) | |
tree | 7b3559368e70ff18c96bd0b15974d085778397a8 /doc/src | |
parent | 6e70443edacfc86674995c0c10ade0aec7a4fddf (diff) | |
download | postgresql-adbe62d04b360bbd408d97e447932d8078485972.tar.gz postgresql-adbe62d04b360bbd408d97e447932d8078485972.zip |
Add PL/Sample to src/test/modules/
PL/Sample is an example template of procedural-language handler. This
can be used as a base to implement a custom PL, or as a facility to test
APIs dedicated to PLs. Much more could be done in this module, like
adding a simple validator, but this is left as future work.
The documentation included originally some C code to understand the
basics of PL handler implementation, but it was outdated, and not really
helpful either if trying to implement a new procedural language,
particularly when it came to the integration of a PL installation with
CREATE EXTENSION.
Author: Mark Wong
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/20200612172648.GA3327@2ndQuadrant.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/plhandler.sgml | 60 |
1 files changed, 4 insertions, 56 deletions
diff --git a/doc/src/sgml/plhandler.sgml b/doc/src/sgml/plhandler.sgml index e1b0af7a60d..40ee59de9f3 100644 --- a/doc/src/sgml/plhandler.sgml +++ b/doc/src/sgml/plhandler.sgml @@ -96,62 +96,10 @@ </para> <para> - This is a template for a procedural-language handler written in C: -<programlisting> -#include "postgres.h" -#include "executor/spi.h" -#include "commands/trigger.h" -#include "fmgr.h" -#include "access/heapam.h" -#include "utils/syscache.h" -#include "catalog/pg_proc.h" -#include "catalog/pg_type.h" - -PG_MODULE_MAGIC; - -PG_FUNCTION_INFO_V1(plsample_call_handler); - -Datum -plsample_call_handler(PG_FUNCTION_ARGS) -{ - Datum retval; - - if (CALLED_AS_TRIGGER(fcinfo)) - { - /* - * Called as a trigger function - */ - TriggerData *trigdata = (TriggerData *) fcinfo->context; - - retval = ... - } - else - { - /* - * Called as a function - */ - - retval = ... - } - - return retval; -} -</programlisting> - Only a few thousand lines of code have to be added instead of the - dots to complete the call handler. - </para> - - <para> - After having compiled the handler function into a loadable module - (see <xref linkend="dfunc"/>), the following commands then - register the sample procedural language: -<programlisting> -CREATE FUNCTION plsample_call_handler() RETURNS language_handler - AS '<replaceable>filename</replaceable>' - LANGUAGE C; -CREATE LANGUAGE plsample - HANDLER plsample_call_handler; -</programlisting> + A template for a procedural-language handler written as a C extension is + provided in <literal>src/test/modules/plsample</literal>. This is a + working sample demonstrating one way to create a procedural-language + handler, process parameters, and return a value. </para> <para> |