summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/man7/CREATE_LANGUAGE.7
blob: ac45c434429c30184fef437389154334710ba736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'\" t
.\"     Title: CREATE LANGUAGE
.\"    Author: The PostgreSQL Global Development Group
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2023
.\"    Manual: PostgreSQL 15.5 Documentation
.\"    Source: PostgreSQL 15.5
.\"  Language: English
.\"
.TH "CREATE LANGUAGE" "7" "2023" "PostgreSQL 15.5" "PostgreSQL 15.5 Documentation"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
CREATE_LANGUAGE \- define a new procedural language
.SH "SYNOPSIS"
.sp
.nf
CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE \fIname\fR
    HANDLER \fIcall_handler\fR [ INLINE \fIinline_handler\fR ] [ VALIDATOR \fIvalfunction\fR ]
CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE \fIname\fR
.fi
.SH "DESCRIPTION"
.PP
\fBCREATE LANGUAGE\fR
registers a new procedural language with a
PostgreSQL
database\&. Subsequently, functions and procedures can be defined in this new language\&.
.PP
\fBCREATE LANGUAGE\fR
effectively associates the language name with handler function(s) that are responsible for executing functions written in the language\&. Refer to
Chapter\ \&58
for more information about language handlers\&.
.PP
\fBCREATE OR REPLACE LANGUAGE\fR
will either create a new language, or replace an existing definition\&. If the language already exists, its parameters are updated according to the command, but the language\*(Aqs ownership and permissions settings do not change, and any existing functions written in the language are assumed to still be valid\&.
.PP
One must have the
PostgreSQL
superuser privilege to register a new language or change an existing language\*(Aqs parameters\&. However, once the language is created it is valid to assign ownership of it to a non\-superuser, who may then drop it, change its permissions, rename it, or assign it to a new owner\&. (Do not, however, assign ownership of the underlying C functions to a non\-superuser; that would create a privilege escalation path for that user\&.)
.PP
The form of
\fBCREATE LANGUAGE\fR
that does not supply any handler function is obsolete\&. For backwards compatibility with old dump files, it is interpreted as
\fBCREATE EXTENSION\fR\&. That will work if the language has been packaged into an extension of the same name, which is the conventional way to set up procedural languages\&.
.SH "PARAMETERS"
.PP
TRUSTED
.RS 4
TRUSTED
specifies that the language does not grant access to data that the user would not otherwise have\&. If this key word is omitted when registering the language, only users with the
PostgreSQL
superuser privilege can use this language to create new functions\&.
.RE
.PP
PROCEDURAL
.RS 4
This is a noise word\&.
.RE
.PP
\fIname\fR
.RS 4
The name of the new procedural language\&. The name must be unique among the languages in the database\&.
.RE
.PP
HANDLER \fIcall_handler\fR
.RS 4
\fIcall_handler\fR
is the name of a previously registered function that will be called to execute the procedural language\*(Aqs functions\&. The call handler for a procedural language must be written in a compiled language such as C with version 1 call convention and registered with
PostgreSQL
as a function taking no arguments and returning the
language_handler
type, a placeholder type that is simply used to identify the function as a call handler\&.
.RE
.PP
INLINE \fIinline_handler\fR
.RS 4
\fIinline_handler\fR
is the name of a previously registered function that will be called to execute an anonymous code block (\fBDO\fR
command) in this language\&. If no
\fIinline_handler\fR
function is specified, the language does not support anonymous code blocks\&. The handler function must take one argument of type
internal, which will be the
\fBDO\fR
command\*(Aqs internal representation, and it will typically return
void\&. The return value of the handler is ignored\&.
.RE
.PP
VALIDATOR \fIvalfunction\fR
.RS 4
\fIvalfunction\fR
is the name of a previously registered function that will be called when a new function in the language is created, to validate the new function\&. If no validator function is specified, then a new function will not be checked when it is created\&. The validator function must take one argument of type
oid, which will be the OID of the to\-be\-created function, and will typically return
void\&.
.sp
A validator function would typically inspect the function body for syntactical correctness, but it can also look at other properties of the function, for example if the language cannot handle certain argument types\&. To signal an error, the validator function should use the
\fBereport()\fR
function\&. The return value of the function is ignored\&.
.RE
.SH "NOTES"
.PP
Use
\fBDROP LANGUAGE\fR
to drop procedural languages\&.
.PP
The system catalog
pg_language
(see
Section\ \&53.29) records information about the currently installed languages\&. Also, the
psql
command
\fB\edL\fR
lists the installed languages\&.
.PP
To create functions in a procedural language, a user must have the
USAGE
privilege for the language\&. By default,
USAGE
is granted to
PUBLIC
(i\&.e\&., everyone) for trusted languages\&. This can be revoked if desired\&.
.PP
Procedural languages are local to individual databases\&. However, a language can be installed into the
template1
database, which will cause it to be available automatically in all subsequently\-created databases\&.
.SH "EXAMPLES"
.PP
A minimal sequence for creating a new procedural language is:
.sp
.if n \{\
.RS 4
.\}
.nf
CREATE FUNCTION plsample_call_handler() RETURNS language_handler
    AS \*(Aq$libdir/plsample\*(Aq
    LANGUAGE C;
CREATE LANGUAGE plsample
    HANDLER plsample_call_handler;
.fi
.if n \{\
.RE
.\}
.sp
Typically that would be written in an extension\*(Aqs creation script, and users would do this to install the extension:
.sp
.if n \{\
.RS 4
.\}
.nf
CREATE EXTENSION plsample;
.fi
.if n \{\
.RE
.\}
.SH "COMPATIBILITY"
.PP
\fBCREATE LANGUAGE\fR
is a
PostgreSQL
extension\&.
.SH "SEE ALSO"
ALTER LANGUAGE (\fBALTER_LANGUAGE\fR(7)), CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7)), DROP LANGUAGE (\fBDROP_LANGUAGE\fR(7)), \fBGRANT\fR(7), \fBREVOKE\fR(7)