mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
More cleanup of CREATE FUNCTION examples.
This commit is contained in:
parent
8dcf998dd1
commit
8394e4723a
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.27 2001/10/02 21:39:35 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.28 2001/10/26 21:17:03 tgl Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<refentry id="SQL-CREATEFUNCTION">
|
<refentry id="SQL-CREATEFUNCTION">
|
||||||
@ -295,14 +295,16 @@ SELECT one() AS answer;
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
The next example creates a C function by calling a routine from a
|
The next example creates a C function by calling a routine from a
|
||||||
user-created shared library. This particular routine calculates a
|
user-created shared library named <filename>funcs.so</> (the extension
|
||||||
check digit and returns TRUE if the check digit in the function
|
may vary across platforms). The shared library file is sought in the
|
||||||
|
server's dynamic library search path. This particular routine calculates
|
||||||
|
a check digit and returns TRUE if the check digit in the function
|
||||||
parameters is correct. It is intended for use in a CHECK
|
parameters is correct. It is intended for use in a CHECK
|
||||||
constraint.
|
constraint.
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION ean_checkdigit(char, char) RETURNS boolean
|
CREATE FUNCTION ean_checkdigit(char, char) RETURNS boolean
|
||||||
AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE C;
|
AS 'funcs' LANGUAGE C;
|
||||||
|
|
||||||
CREATE TABLE product (
|
CREATE TABLE product (
|
||||||
id char(8) PRIMARY KEY,
|
id char(8) PRIMARY KEY,
|
||||||
@ -318,7 +320,9 @@ CREATE TABLE product (
|
|||||||
This example creates a function that does type conversion between the
|
This example creates a function that does type conversion between the
|
||||||
user-defined type complex, and the internal type point. The
|
user-defined type complex, and the internal type point. The
|
||||||
function is implemented by a dynamically loaded object that was
|
function is implemented by a dynamically loaded object that was
|
||||||
compiled from C source. For <productname>PostgreSQL</productname> to
|
compiled from C source (we illustrate the now-deprecated alternative
|
||||||
|
of specifying the exact pathname to the shared object file).
|
||||||
|
For <productname>PostgreSQL</productname> to
|
||||||
find a type conversion function automatically, the SQL function has
|
find a type conversion function automatically, the SQL function has
|
||||||
to have the same name as the return type, and so overloading is
|
to have the same name as the return type, and so overloading is
|
||||||
unavoidable. The function name is overloaded by using the second
|
unavoidable. The function name is overloaded by using the second
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.17 2001/09/06 10:28:39 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.18 2001/10/26 21:17:03 tgl Exp $
|
||||||
Postgres documentation
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ ERROR: PL handler function <replaceable class="parameter">funcname</replaceable
|
|||||||
This command normally should not be executed directly by users.
|
This command normally should not be executed directly by users.
|
||||||
For the procedural languages supplied in the
|
For the procedural languages supplied in the
|
||||||
<productname>PostgreSQL</productname> distribution, the <xref
|
<productname>PostgreSQL</productname> distribution, the <xref
|
||||||
linkend="app-createlang"> program should be used, which will also
|
linkend="app-createlang"> script should be used, which will also
|
||||||
install the correct call handler. (<command>createlang</command>
|
install the correct call handler. (<command>createlang</command>
|
||||||
will call <command>CREATE LANGUAGE</command> internally.)
|
will call <command>CREATE LANGUAGE</command> internally.)
|
||||||
</para>
|
</para>
|
||||||
@ -183,7 +183,7 @@ ERROR: PL handler function <replaceable class="parameter">funcname</replaceable
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
Use <xref linkend="sql-droplanguage">, or better yet the <xref
|
Use <xref linkend="sql-droplanguage">, or better yet the <xref
|
||||||
linkend="app-droplang"> program, to drop procedural languages.
|
linkend="app-droplang"> script, to drop procedural languages.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -210,7 +210,7 @@ ERROR: PL handler function <replaceable class="parameter">funcname</replaceable
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
At present, the definition of a procedural language cannot be
|
At present, the definition of a procedural language cannot be
|
||||||
changed once is has been created.
|
changed once it has been created.
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ ERROR: PL handler function <replaceable class="parameter">funcname</replaceable
|
|||||||
procedural language and the associated call handler.
|
procedural language and the associated call handler.
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION plsample_call_handler () RETURNS opaque
|
CREATE FUNCTION plsample_call_handler () RETURNS opaque
|
||||||
AS '/usr/local/pgsql/lib/plsample.so'
|
AS '$libdir/plsample'
|
||||||
LANGUAGE C;
|
LANGUAGE C;
|
||||||
CREATE LANGUAGE plsample
|
CREATE LANGUAGE plsample
|
||||||
HANDLER plsample_call_handler;
|
HANDLER plsample_call_handler;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.18 2001/10/22 23:48:11 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.19 2001/10/26 21:17:03 tgl Exp $
|
||||||
Postgres documentation
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -44,7 +44,8 @@ Postgres documentation
|
|||||||
<term><replaceable class="parameter">langname</replaceable></term>
|
<term><replaceable class="parameter">langname</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies the name of the backend programming language to be defined.
|
Specifies the name of the procedural programming language to be
|
||||||
|
defined.
|
||||||
<application>createlang</application> will prompt for
|
<application>createlang</application> will prompt for
|
||||||
<replaceable class="parameter">langname</replaceable>
|
<replaceable class="parameter">langname</replaceable>
|
||||||
if it is not specified on the command line.
|
if it is not specified on the command line.
|
||||||
@ -56,7 +57,7 @@ Postgres documentation
|
|||||||
<term>-d, --dbname <replaceable class="parameter">dbname</replaceable></term>
|
<term>-d, --dbname <replaceable class="parameter">dbname</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies which database the language should be added.
|
Specifies to which database the language should be added.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -85,7 +86,8 @@ Postgres documentation
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies the directory in which the language interpreter is
|
Specifies the directory in which the language interpreter is
|
||||||
to be found. This is normally found automatically.
|
to be found. Use of this option is deprecated; the directory
|
||||||
|
is normally found automatically.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_language.sgml,v 1.11 2001/09/03 12:57:49 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_language.sgml,v 1.12 2001/10/26 21:17:03 tgl Exp $
|
||||||
Postgres documentation
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<refentry id="SQL-DROPLANGUAGE">
|
<refentry id="SQL-DROPLANGUAGE">
|
||||||
<refmeta>
|
<refmeta>
|
||||||
<refentrytitle id="SQL-DROPLANGUAGE-TITLE">
|
<refentrytitle id="SQL-DROPLANGUAGE-TITLE">DROP LANGUAGE</refentrytitle>
|
||||||
DROP LANGUAGE
|
|
||||||
</refentrytitle>
|
|
||||||
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
||||||
</refmeta>
|
</refmeta>
|
||||||
<refnamediv>
|
<refnamediv>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.39 2001/10/26 19:58:12 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.40 2001/10/26 21:17:03 tgl Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<chapter id="xfunc">
|
<chapter id="xfunc">
|
||||||
@ -1054,25 +1054,25 @@ concat_text(text *arg1, text *arg2)
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION add_one(int4) RETURNS int4
|
CREATE FUNCTION add_one(int4) RETURNS int4
|
||||||
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE 'c'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE C
|
||||||
WITH (isStrict);
|
WITH (isStrict);
|
||||||
|
|
||||||
-- note overloading of SQL function name add_one()
|
-- note overloading of SQL function name add_one()
|
||||||
CREATE FUNCTION add_one(float8) RETURNS float8
|
CREATE FUNCTION add_one(float8) RETURNS float8
|
||||||
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs',
|
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs',
|
||||||
'add_one_float8'
|
'add_one_float8'
|
||||||
LANGUAGE 'c' WITH (isStrict);
|
LANGUAGE C WITH (isStrict);
|
||||||
|
|
||||||
CREATE FUNCTION makepoint(point, point) RETURNS point
|
CREATE FUNCTION makepoint(point, point) RETURNS point
|
||||||
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE 'c'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE C
|
||||||
WITH (isStrict);
|
WITH (isStrict);
|
||||||
|
|
||||||
CREATE FUNCTION copytext(text) RETURNS text
|
CREATE FUNCTION copytext(text) RETURNS text
|
||||||
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE 'c'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE C
|
||||||
WITH (isStrict);
|
WITH (isStrict);
|
||||||
|
|
||||||
CREATE FUNCTION concat_text(text, text) RETURNS text
|
CREATE FUNCTION concat_text(text, text) RETURNS text
|
||||||
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE 'c'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs' LANGUAGE C
|
||||||
WITH (isStrict);
|
WITH (isStrict);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
@ -1358,8 +1358,8 @@ c_overpaid(PG_FUNCTION_ARGS)
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION c_overpaid(emp, int4)
|
CREATE FUNCTION c_overpaid(emp, int4)
|
||||||
RETURNS bool
|
RETURNS bool
|
||||||
AS '<replaceable>PGROOT</replaceable>/tutorial/obj/funcs'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/funcs'
|
||||||
LANGUAGE 'c';
|
LANGUAGE C;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.19 2001/09/13 15:55:23 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.20 2001/10/26 21:17:03 tgl Exp $
|
||||||
Postgres documentation
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -313,7 +313,9 @@ SELECT oid, *
|
|||||||
<para>
|
<para>
|
||||||
Suppose the code that implements these functions
|
Suppose the code that implements these functions
|
||||||
is stored in the file
|
is stored in the file
|
||||||
<filename>PGROOT/src/tutorial/complex.c</filename>.
|
<replaceable>PGROOT</replaceable><filename>/tutorial/complex.c</filename>,
|
||||||
|
which we have compiled into
|
||||||
|
<replaceable>PGROOT</replaceable><filename>/tutorial/complex.so</filename>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -339,8 +341,8 @@ SELECT oid, *
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION complex_abs_eq(complex, complex)
|
CREATE FUNCTION complex_abs_eq(complex, complex)
|
||||||
RETURNS bool
|
RETURNS bool
|
||||||
AS 'PGROOT/tutorial/obj/complex.so'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/complex'
|
||||||
LANGUAGE 'c';
|
LANGUAGE C;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -489,8 +491,8 @@ CREATE OPERATOR = (
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION complex_abs_cmp(complex, complex)
|
CREATE FUNCTION complex_abs_cmp(complex, complex)
|
||||||
RETURNS int4
|
RETURNS int4
|
||||||
AS 'PGROOT/tutorial/obj/complex.so'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/complex'
|
||||||
LANGUAGE 'c';
|
LANGUAGE C;
|
||||||
|
|
||||||
SELECT oid, proname FROM pg_proc
|
SELECT oid, proname FROM pg_proc
|
||||||
WHERE proname = 'complex_abs_cmp';
|
WHERE proname = 'complex_abs_cmp';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/xoper.sgml,v 1.14 2001/09/13 15:55:23 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/xoper.sgml,v 1.15 2001/10/26 21:17:03 tgl Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Chapter Id="xoper">
|
<Chapter Id="xoper">
|
||||||
@ -38,8 +38,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/xoper.sgml,v 1.14 2001/09/13 15:55:23 peter
|
|||||||
<ProgramListing>
|
<ProgramListing>
|
||||||
CREATE FUNCTION complex_add(complex, complex)
|
CREATE FUNCTION complex_add(complex, complex)
|
||||||
RETURNS complex
|
RETURNS complex
|
||||||
AS '$PWD/obj/complex.so'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/complex'
|
||||||
LANGUAGE 'c';
|
LANGUAGE C;
|
||||||
|
|
||||||
CREATE OPERATOR + (
|
CREATE OPERATOR + (
|
||||||
leftarg = complex,
|
leftarg = complex,
|
||||||
|
@ -110,13 +110,13 @@ complex_out(Complex *complex)
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION complex_in(opaque)
|
CREATE FUNCTION complex_in(opaque)
|
||||||
RETURNS complex
|
RETURNS complex
|
||||||
AS 'PGROOT/tutorial/obj/complex.so'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/complex'
|
||||||
LANGUAGE 'c';
|
LANGUAGE C;
|
||||||
|
|
||||||
CREATE FUNCTION complex_out(opaque)
|
CREATE FUNCTION complex_out(opaque)
|
||||||
RETURNS opaque
|
RETURNS opaque
|
||||||
AS 'PGROOT/tutorial/obj/complex.so'
|
AS '<replaceable>PGROOT</replaceable>/tutorial/complex'
|
||||||
LANGUAGE 'c';
|
LANGUAGE C;
|
||||||
|
|
||||||
CREATE TYPE complex (
|
CREATE TYPE complex (
|
||||||
internallength = 16,
|
internallength = 16,
|
||||||
|
Loading…
Reference in New Issue
Block a user