Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/xplang.sgml`
df5b04e963ed3c1f0f32ac3dcdb2bcc78d9b705b2740cab80000000100000cd6
 must be carried out by a database superuser.  In most cases
     the required SQL commands should be packaged as the installation script
     of an <quote>extension</quote>, so that <command>CREATE EXTENSION</command> can be
     used to execute them.
    </para>

    <step performance="required" id="xplang-install-cr1">
     <para>
      The shared object for the language handler must be compiled and
      installed into an appropriate library directory.  This works in the same
      way as building and installing modules with regular user-defined C
      functions does; see <xref linkend="dfunc"/>.  Often, the language
      handler will depend on an external library that provides the actual
      programming language engine; if so, that must be installed as well.
     </para>
    </step>

    <step performance="required" id="xplang-install-cr2">
     <para>
      The handler must be declared with the command
<synopsis>
CREATE FUNCTION <replaceable>handler_function_name</replaceable>()
    RETURNS language_handler
    AS '<replaceable>path-to-shared-object</replaceable>'
    LANGUAGE C;
</synopsis>
      The special return type of <type>language_handler</type> tells
      the database system that this function does not return one of
      the defined <acronym>SQL</acronym> data types and is not directly usable
      in <acronym>SQL</acronym> statements.
     </para>
    </step>

    <step performance="optional" id="xplang-install-cr3">
     <para>
      Optionally, the language handler can provide an <quote>inline</quote>
      handler function that executes anonymous code blocks
      (<link linkend="sql-do"><command>DO</command></link> commands)
      written in this language.  If an inline handler function
      is provided by the language, declare it with a command like
<synopsis>
CREATE FUNCTION <replaceable>inline_function_name</replaceable>(internal)
    RETURNS void
    AS '<replaceable>path-to-shared-object</replaceable>'
    LANGUAGE C;
</synopsis>
     </para>
    </step>

    <step performance="optional" id="xplang-install-cr4">
     <para>
      Optionally, the language handler can provide a <quote>validator</quote>
      function that checks a function definition for correctness without
      actually executing it.  The validator function is called by
      <command>CREATE FUNCTION</command> if it exists.  If a validator function
      is provided by the language, declare it with a command like
<synopsis>
CREATE FUNCTION <replaceable>validator_function_name</replaceable>(oid)
    RETURNS void
    AS '<replaceable>path-to-shared-object</replaceable>'
    LANGUAGE C STRICT;
</synopsis>
     </para>
    </step>

    <step performance="required" id="xplang-install-cr5">
     <para>
      Finally, the PL must be declared with the command
<synopsis>
CREATE <optional>TRUSTED</optional> LANGUAGE <replaceable>language_name</replaceable>
    HANDLER <replaceable>handler_function_name</replaceable>
    <optional>INLINE <replaceable>inline_function_name</replaceable></optional>
    <optional>VALIDATOR <replaceable>validator_function_name</replaceable></optional> ;
</synopsis>
      The optional key word <literal>TRUSTED</literal> specifies that
      the language does not grant access to data that the user would
      not

Title: Manual Installation of Procedural Languages in PostgreSQL
Summary
This section details the manual process for installing a procedural language in PostgreSQL, which must be performed by a database superuser. The process involves five steps: 1) Compiling and installing the language handler's shared object, 2) Declaring the handler function, 3) Optionally declaring an inline handler function for executing anonymous code blocks, 4) Optionally declaring a validator function to check function definitions, and 5) Declaring the procedural language itself. The text emphasizes that these steps are typically packaged as an extension installation script, allowing for easier installation using the CREATE EXTENSION command.