Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cfe951

Browse files
committed
CREATE PROCEDURAL LANGUAGE mans (Jan).
1 parent43514b8 commit6cfe951

File tree

3 files changed

+180
-3
lines changed

3 files changed

+180
-3
lines changed

‎src/man/create_function.l

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/create_function.l,v 1.3 1997/09/10 20:19:23 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/create_function.l,v 1.4 1997/10/30 05:38:17 vadim Exp $
44
.TH "CREATE FUNCTION" SQL 11/05/95 PostgreSQL PostgreSQL
55
.SH "NAME"
66
create function\(em define a new function
@@ -10,7 +10,7 @@ create function \(em define a new function
1010
\fB(\fP[type1 {, type-n}]\fB)\fP
1111
\fBreturns\fP type-r
1212
\fBas\fP {'/full/path/to/objectfile' | 'sql-queries'}
13-
\fBlanguage\fP {'c'\'sql'\'internal'}
13+
\fBlanguage\fP {'c'\'sql'\'internal'\'plname'}
1414
.fi
1515
.SH "DESCRIPTION"
1616
With this command, a Postgres user can register a function with Postgres.
@@ -29,6 +29,12 @@ or
2929
.IR"\*(lqsql\*(rq".
3030
or
3131
.IR"\*(lqinternal\*(rq".
32+
or
33+
.IR"\*(lqplname\*(rq".
34+
(The
35+
.IR"plname"
36+
is the language name of a created procedural language. See
37+
create language(l) for details.)
3238
(The
3339
.IR"arg is"
3440
clause may be left out if the function has no arguments, or
@@ -291,6 +297,12 @@ a $n syntax: $1 refers to the first argument, $2 to the second, and so
291297
on. If an argument is complex, then a\*(lqdot\*(rq notation may be
292298
used to access attributes of the argument (e.g.\*(lq$1.emp\*(rq), or
293299
to invoke functions via a nested-dot syntax.
300+
.SH "PL FUNCTIONS"
301+
Procedural languages aren't builtin to Postgres. They are offered
302+
by loadable modules. Please refer to the documentation for the
303+
PL in question for details about the syntax and how the
304+
.IR"as"
305+
clause is interpreted by the PL handler.
294306
.SH "EXAMPLES: C Functions"
295307
The following command defines a C function, overpaid, of two basetype
296308
arguments.
@@ -378,7 +390,7 @@ select function hobbies (EMP) returns set of HOBBIES
378390
language 'sql'
379391
.SH "SEE ALSO"
380392
.PP
381-
information(1), load(l), drop function(l).
393+
information(1), load(l), drop function(l), create language(l).
382394
.SH "NOTES"
383395
.SH "Name Space Conflicts"
384396
More than one function may be defined with the same name, as long as

‎src/man/create_language.l

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
.\" This is -*-nroff-*-
2+
.\" XXX standard disclaimer belongs here....
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/create_language.l,v 1.1 1997/10/30 05:38:19 vadim Exp $
4+
.TH "CREATE LANGUAGE" SQL 11/05/95 PostgreSQL PostgreSQL
5+
.SH "NAME"
6+
create language\(em define a new language for functions
7+
.SH "SYNOPSIS"
8+
.nf
9+
\fBcreate\fP [\fBtrusted\fP]\fBprocedurallanguage\fP 'lanname'
10+
\fBhandler\fP call_handler
11+
\fBlancompiler\fP 'comment'
12+
.fi
13+
.SH "DESCRIPTION"
14+
With this command, a Postgres user can register a new language with
15+
Postgres. Subsequently, functions and trigger procedures can be
16+
defined in this new language. The user must have the Postgres superuser
17+
privilege to register a new language.
18+
.PP
19+
The lanname is the name of the new procedural language. It is converted
20+
to lower case before the new entry in the pg_language system catalog
21+
is inserted. Note that this case translation is also done on
22+
create function(l) and drop language(l). Thus, the language name
23+
is case insensitive. A procedural language cannot override one of the
24+
builtin languages of Postgres.
25+
.PP
26+
The argument for\fBhandler\fP
27+
is the name of a previously registered function that
28+
will be called to execute the PL procedures.
29+
.PP
30+
The\fBlancompiler\fP argument is the string that will be inserted
31+
in the lancompiler attribute of the new pg_language entry. Up to now,
32+
Postgres doesn't use this attribute in any way.
33+
.PP
34+
The\fBtrusted\fP keyword specifies, that the call handler for the
35+
language is safe - i.e. it offers an unprivileged user no functionality
36+
to get around access restrictions. If this keyword is omitted when
37+
registering the language, only users with the Postgres superuser privilege
38+
can use this language to create new functions (like the 'C' language).
39+
.SH "WRITING PL HANDLERS"
40+
The call handler for a procedural language must be written in a compiler
41+
language such as 'C' and registered with Postgres as a function taking
42+
no arguments and returning
43+
.IR"opaque"
44+
type. This prevents the call handler from beeing called directly as a function
45+
from queries.
46+
But there are arguments
47+
on the actual call when a PL function or trigger procedure in the
48+
language offered by the handler is to be executed.
49+
.PP
50+
When called from the trigger manager, the only argument is the object ID from
51+
the procedures pg_proc entry. All other information from the trigger manager
52+
is found in the global CurrentTriggerData pointer.
53+
.PP
54+
When called from the function manager, the arguments are the object ID of the
55+
procedures pg_proc entry, the number of arguments given to the PL function,
56+
the arguments in a FmgrValues structure and a pointer to a boolean where the
57+
function tells the caller if the return value is the SQL NULL value.
58+
.PP
59+
It's up to the call handler to fetch the pg_proc entry
60+
and to analyze the argument and return types of the called procedure.
61+
the
62+
.IR"as"
63+
clause from the create function(l) of the procedure will be found in
64+
the prosrc attribute of the pg_proc entry. This may be the source text
65+
in the procedural language itself (like for PL/Tcl), a pathname to a
66+
file or anything else that tells the call handler what to do in detail.
67+
.SH "EXAMPLE"
68+
Following is a template for a PL handler written in 'C':
69+
.nf
70+
71+
#include "executor/spi.h"
72+
#include "commands/trigger.h"
73+
#include "utils/elog.h"
74+
#include "fmgr.h"/* for FmgrValues struct */
75+
#include "access/heapam.h"
76+
#include "utils/syscache.h"
77+
#include "catalog/pg_proc.h"
78+
#include "catalog/pg_type.h"
79+
80+
Datum
81+
plsample_call_handler(
82+
Oidprooid,
83+
intpronargs,
84+
FmgrValues*proargs,
85+
bool*isNull)
86+
{
87+
Datumretval;
88+
TriggerData*trigdata;
89+
90+
if (CurrentTriggerData == NULL) {
91+
/*
92+
* Called as a function
93+
*/
94+
95+
retval = ...
96+
} else {
97+
/*
98+
* Called as a trigger procedure
99+
*/
100+
trigdata = CurrentTriggerData;
101+
CurrentTriggerData = NULL;
102+
103+
retval = ...
104+
}
105+
106+
*isNull = false;
107+
return retval;
108+
}
109+
110+
.fi
111+
Only a few thousand lines of code have to be added instead of the dots
112+
to complete the PL call handler. See create function(l) how to compile
113+
it into a loadable module. The following commands then register the
114+
sample procedural language.
115+
.nf
116+
117+
create function plsample_call_handler () returns opaque
118+
as '/usr/local/pgsql/lib/plsample.so'
119+
language 'C';
120+
121+
create procedural language 'plsample'
122+
handler plsample_call_handler
123+
lancompiler 'PL/Sample';
124+
125+
.fi
126+
.SH "SEE ALSO"
127+
.PP
128+
create function(l), drop language(l).
129+
.SH "RESTRICTIONS"
130+
Since the call handler for a procedural language must be
131+
registered with Postgres in the 'C' language, it inherits
132+
all the restrictions of 'C' functions.
133+
.SH "BUGS"
134+
Currently, the definitions for a procedural language once
135+
created cannot be changed.

‎src/man/drop_language.l

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.\" This is -*-nroff-*-
2+
.\" XXX standard disclaimer belongs here....
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/drop_language.l,v 1.1 1997/10/30 05:38:20 vadim Exp $
4+
.TH "DROP LANGUAGE" SQL 11/05/95 PostgreSQL PostgreSQL
5+
.SH NAME
6+
drop language\(em remove a user-defined procedural language
7+
.SH SYNOPSIS
8+
.nf
9+
\fBdropprocedurallanguage\fR 'lanname'
10+
.fi
11+
.SH DESCRIPTION
12+
.BR"drop procedural language"
13+
will remove the definition of the previously registered PL with the
14+
name
15+
.IR lanname.
16+
.SH EXAMPLE
17+
.nf
18+
--
19+
--this command removes the PL/Sample language
20+
--
21+
drop procedural language 'plsample';
22+
.fi
23+
.SH "SEE ALSO"
24+
create language(l).
25+
.SH BUGS
26+
No checks are made if functions or trigger procedures registered
27+
in this language still exist. To reenable them without having to
28+
drop and recreate all the functions, the pg_proc's prolang attribute
29+
of the functions must be adjusted to the new object ID of the
30+
recreated pg_language entry for the PL.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp