Skip to content

Commit ee8ed85

Browse files
committed
Make LANCOMPILER clause in CREATE LANGUAGE optional. Allow "identifier"
syntax for language names (instead of 'string'). createlang now handles the case where a second language uses the same call handler as an already installed language (e.g., plperl/plperlu). droplang now handles the reverse case, i.e., dropping a language where the call handler is still used by another language. Moreover, droplang can now be used to drop any user-defined language, not just the supplied ones.
1 parent 38cfc95 commit ee8ed85

File tree

7 files changed

+118
-123
lines changed

7 files changed

+118
-123
lines changed

doc/src/sgml/ref/create_function.sgml

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.24 2001/06/04 23:27:23 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.25 2001/08/13 21:34:51 petere Exp $
33
-->
44

55
<refentry id="SQL-CREATEFUNCTION">
@@ -18,12 +18,12 @@ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.24 2001/06/04
1818
CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] )
1919
RETURNS <replaceable class="parameter">rettype</replaceable>
2020
AS '<replaceable class="parameter">definition</replaceable>'
21-
LANGUAGE '<replaceable class="parameter">langname</replaceable>'
21+
LANGUAGE <replaceable class="parameter">langname</replaceable>
2222
[ WITH ( <replaceable class="parameter">attribute</replaceable> [, ...] ) ]
2323
CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] )
2424
RETURNS <replaceable class="parameter">rettype</replaceable>
2525
AS '<replaceable class="parameter">obj_file</replaceable>', '<replaceable class="parameter">link_symbol</replaceable>'
26-
LANGUAGE '<replaceable class="parameter">langname</replaceable>'
26+
LANGUAGE <replaceable class="parameter">langname</replaceable>
2727
[ WITH ( <replaceable class="parameter">attribute</replaceable> [, ...] ) ]
2828
</synopsis>
2929
</refsynopsisdiv>
@@ -123,13 +123,14 @@ CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceab
123123

124124
<listitem>
125125
<para>
126-
May be '<literal>sql</literal>', '<literal>C</literal>',
127-
'<literal>internal</literal>', or '<replaceable
128-
class="parameter">plname</replaceable>', where '<replaceable
129-
class="parameter">plname</replaceable>' is the name of a
126+
May be <literal>SQL</literal>, <literal>C</literal>,
127+
<literal>internal</literal>, or <replaceable
128+
class="parameter">plname</replaceable>, where <replaceable
129+
class="parameter">plname</replaceable> is the name of a
130130
created procedural language. See
131131
<xref linkend="sql-createlanguage">
132-
for details.
132+
for details. For backward compatibility, the name may be
133+
enclosed by single quotes.
133134
</para>
134135
</listitem>
135136
</varlistentry>
@@ -261,7 +262,7 @@ CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceab
261262
<programlisting>
262263
CREATE FUNCTION one() RETURNS integer
263264
AS 'SELECT 1 AS RESULT;'
264-
LANGUAGE 'sql';
265+
LANGUAGE SQL;
265266

266267
SELECT one() AS answer;
267268
<computeroutput>
@@ -281,7 +282,7 @@ SELECT one() AS answer;
281282

282283
<programlisting>
283284
CREATE FUNCTION ean_checkdigit(char, char) RETURNS boolean
284-
AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE 'c';
285+
AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE C;
285286

286287
CREATE TABLE product (
287288
id char(8) PRIMARY KEY,
@@ -306,7 +307,7 @@ CREATE TABLE product (
306307
<programlisting>
307308
CREATE FUNCTION point(complex) RETURNS point
308309
AS '/home/bernie/pgsql/lib/complex.so', 'complex_to_point'
309-
LANGUAGE 'c';
310+
LANGUAGE C;
310311
</programlisting>
311312

312313
The C declaration of the function could be:

doc/src/sgml/ref/create_language.sgml

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.14 2000/11/20 20:36:46 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.15 2001/08/13 21:34:51 petere Exp $
33
Postgres documentation
44
-->
55

@@ -23,9 +23,8 @@ Postgres documentation
2323
<date>1999-07-20</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langname</replaceable>'
26+
CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">langname</replaceable>
2727
HANDLER <replaceable class="parameter">call_handler</replaceable>
28-
LANCOMPILER '<replaceable class="parameter">comment</replaceable>'
2928
</synopsis>
3029

3130
<refsect2 id="R2-SQL-CREATELANGUAGE-1">
@@ -62,6 +61,10 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langn
6261
language cannot override one of the built-in languages of
6362
<productname>Postgres</productname>.
6463
</para>
64+
<para>
65+
For backward compatibility, the name may be enclosed by single
66+
quotes.
67+
</para>
6568
</listitem>
6669
</varlistentry>
6770

@@ -77,20 +80,6 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langn
7780
</listitem>
7881
</varlistentry>
7982

80-
<varlistentry>
81-
<term><replaceable class="parameter">comment</replaceable></term>
82-
<listitem>
83-
<para>
84-
The <function>LANCOMPILER</function> argument is the
85-
string that will be
86-
inserted in the <literal>LANCOMPILER</literal> attribute
87-
of the new
88-
<filename>pg_language</filename> entry. At present,
89-
<productname>Postgres</productname> does not use
90-
this attribute in any way.
91-
</para>
92-
</listitem>
93-
</varlistentry>
9483
</variablelist>
9584
</para>
9685

@@ -346,10 +335,9 @@ plsample_call_handler(PG_FUNCTION_ARGS)
346335
<programlisting>
347336
CREATE FUNCTION plsample_call_handler () RETURNS opaque
348337
AS '/usr/local/pgsql/lib/plsample.so'
349-
LANGUAGE 'C';
350-
CREATE PROCEDURAL LANGUAGE 'plsample'
351-
HANDLER plsample_call_handler
352-
LANCOMPILER 'PL/Sample';
338+
LANGUAGE C;
339+
CREATE LANGUAGE plsample
340+
HANDLER plsample_call_handler;
353341
</programlisting>
354342
</para>
355343
</refsect1>

doc/src/sgml/ref/drop_language.sgml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_language.sgml,v 1.9 2000/12/25 23:15:26 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_language.sgml,v 1.10 2001/08/13 21:34:51 petere Exp $
33
Postgres documentation
44
-->
55

@@ -23,7 +23,7 @@ Postgres documentation
2323
<date>1999-07-20</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
DROP [ PROCEDURAL ] LANGUAGE '<replaceable class="PARAMETER">name</replaceable>'
26+
DROP [ PROCEDURAL ] LANGUAGE <replaceable class="PARAMETER">name</replaceable>
2727
</synopsis>
2828

2929
<refsect2 id="R2-SQL-DROPLANGUAGE-1">
@@ -40,7 +40,8 @@ DROP [ PROCEDURAL ] LANGUAGE '<replaceable class="PARAMETER">name</replaceable>'
4040
<term><replaceable class="PARAMETER">name</replaceable></term>
4141
<listitem>
4242
<para>
43-
The name of an existing procedural language.
43+
The name of an existing procedural language. For backward
44+
compatibility, the name may be enclosed by single quotes.
4445
</para>
4546
</listitem>
4647
</varlistentry>
@@ -132,7 +133,7 @@ ERROR: Language "<replaceable class="parameter">name</replaceable>" doesn't exis
132133
This command removes the PL/Sample language:
133134

134135
<programlisting>
135-
DROP PROCEDURAL LANGUAGE 'plsample';
136+
DROP LANGUAGE plsample;
136137
</programlisting>
137138
</para>
138139
</refsect1>

doc/src/sgml/xplang.sgml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/xplang.sgml,v 1.13 2001/05/19 09:01:10 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/xplang.sgml,v 1.14 2001/08/13 21:34:51 petere Exp $
33
-->
44

55
<chapter id="xplang">
@@ -79,7 +79,7 @@ createlang plpgsql template1
7979
<synopsis>
8080
CREATE FUNCTION <replaceable>handler_function_name</replaceable> ()
8181
RETURNS OPAQUE AS
82-
'<replaceable>path-to-shared-object</replaceable>' LANGUAGE 'C';
82+
'<replaceable>path-to-shared-object</replaceable>' LANGUAGE C;
8383
</synopsis>
8484
The special return type of <type>OPAQUE</type> tells
8585
the database that this function does not return one of
@@ -92,9 +92,8 @@ CREATE FUNCTION <replaceable>handler_function_name</replaceable> ()
9292
<para>
9393
The PL must be declared with the command
9494
<synopsis>
95-
CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE '<replaceable>language-name</replaceable>'
96-
HANDLER <replaceable>handler_function_name</replaceable>
97-
LANCOMPILER '<replaceable>description</replaceable>';
95+
CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE <replaceable>language-name</replaceable>
96+
HANDLER <replaceable>handler_function_name</replaceable>;
9897
</synopsis>
9998
The optional key word <token>TRUSTED</token> tells
10099
whether ordinary database users that have no superuser
@@ -130,7 +129,7 @@ CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE '<r
130129

131130
<programlisting>
132131
CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
133-
'$libdir/plpgsql' LANGUAGE 'C';
132+
'$libdir/plpgsql' LANGUAGE C;
134133
</programlisting>
135134
</para>
136135
</step>
@@ -139,9 +138,8 @@ CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
139138
<para>
140139
The command
141140
<programlisting>
142-
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
143-
HANDLER plpgsql_call_handler
144-
LANCOMPILER 'PL/pgSQL';
141+
CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
142+
HANDLER plpgsql_call_handler;
145143
</programlisting>
146144
then defines that the previously declared call handler function
147145
should be invoked for functions and trigger procedures where the

src/backend/parser/gram.y

+12-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.243 2001/08/10 18:57:36 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.244 2001/08/13 21:34:51 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -163,7 +163,8 @@ static void doNegateFloat(Value *v);
163163
%type <list> OptUserList
164164
%type <defelt> OptUserElem
165165

166-
%type <boolean> TriggerActionTime, TriggerForSpec, PLangTrusted, opt_procedural
166+
%type <boolean> TriggerActionTime, TriggerForSpec, opt_trusted, opt_procedural
167+
%type <str> opt_lancompiler
167168

168169
%type <str> OptConstrFromTable
169170

@@ -1688,23 +1689,26 @@ IntegerOnly: Iconst
16881689
*
16891690
*****************************************************************************/
16901691

1691-
CreatePLangStmt: CREATE PLangTrusted opt_procedural LANGUAGE Sconst
1692-
HANDLER func_name LANCOMPILER Sconst
1692+
CreatePLangStmt: CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
1693+
HANDLER func_name opt_lancompiler
16931694
{
16941695
CreatePLangStmt *n = makeNode(CreatePLangStmt);
16951696
n->plname = $5;
16961697
n->plhandler = $7;
1697-
n->plcompiler = $9;
1698+
n->plcompiler = $8;
16981699
n->pltrusted = $2;
16991700
$$ = (Node *)n;
17001701
}
17011702
;
17021703

1703-
PLangTrusted: TRUSTED { $$ = TRUE; }
1704+
opt_trusted: TRUSTED { $$ = TRUE; }
17041705
| /*EMPTY*/ { $$ = FALSE; }
17051706
;
17061707

1707-
DropPLangStmt: DROP opt_procedural LANGUAGE Sconst
1708+
opt_lancompiler: LANCOMPILER Sconst { $$ = $2; }
1709+
| /*EMPTY*/ { $$ = ""; }
1710+
1711+
DropPLangStmt: DROP opt_procedural LANGUAGE ColId_or_Sconst
17081712
{
17091713
DropPLangStmt *n = makeNode(DropPLangStmt);
17101714
n->plname = $4;
@@ -2511,7 +2515,7 @@ RecipeStmt: EXECUTE RECIPE recipe_name
25112515
*****************************************************************************/
25122516

25132517
ProcedureStmt: CREATE FUNCTION func_name func_args
2514-
RETURNS func_return AS func_as LANGUAGE Sconst opt_with
2518+
RETURNS func_return AS func_as LANGUAGE ColId_or_Sconst opt_with
25152519
{
25162520
ProcedureStmt *n = makeNode(ProcedureStmt);
25172521
n->funcname = $3;

0 commit comments

Comments
 (0)