+ class="parameter">plname
, where
+ class="parameter">plname is the name of a
created procedural language. See
- for details.
+ for details. For backward compatibility, the name may be
+ enclosed by single quotes.
CREATE FUNCTION one() RETURNS integer
AS 'SELECT 1 AS RESULT;'
- LANGUAGE 'sql';
+ LANGUAGE SQL;
SELECT one() AS answer;
CREATE FUNCTION ean_checkdigit(char, char) RETURNS boolean
- AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE 'c';
+ AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE C;
CREATE TABLE product (
id char(8) PRIMARY KEY,
CREATE FUNCTION point(complex) RETURNS point
AS '/home/bernie/pgsql/lib/complex.so', 'complex_to_point'
- LANGUAGE 'c';
+ LANGUAGE C;
The C declaration of the function could be:
1999-07-20
-CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE 'langname'
+CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE langname
HANDLER call_handler
- LANCOMPILER 'comment'
language cannot override one of the built-in languages of
+ For backward compatibility, the name may be enclosed by single
+ quotes.
+
-
- comment
-
- The LANCOMPILER argument is the
- string that will be
- inserted in the LANCOMPILER attribute
- of the new
- pg_language entry. At present,
- this attribute in any way.
-
-
-
CREATE FUNCTION plsample_call_handler () RETURNS opaque
AS '/usr/local/pgsql/lib/plsample.so'
- LANGUAGE 'C';
-CREATE PROCEDURAL LANGUAGE 'plsample'
- HANDLER plsample_call_handler
- LANCOMPILER 'PL/Sample';
+ LANGUAGE C;
+CREATE LANGUAGE plsample
+ HANDLER plsample_call_handler;
1999-07-20
-DROP [ PROCEDURAL ] LANGUAGE 'name'
+DROP [ PROCEDURAL ] LANGUAGE name
name
- The name of an existing procedural language.
+ The name of an existing procedural language. For backward
+ compatibility, the name may be enclosed by single quotes.
This command removes the PL/Sample language:
-DROP PROCEDURAL LANGUAGE 'plsample';
+DROP LANGUAGE plsample;
CREATE FUNCTION handler_function_name ()
RETURNS OPAQUE AS
- 'path-to-shared-object' LANGUAGE 'C';
+ 'path-to-shared-object' LANGUAGE C;
The special return type of OPAQUE tells
the database that this function does not return one of
The PL must be declared with the command
-CREATE TRUSTED PROCEDURAL LANGUAGE 'language-name'
- HANDLER handler_function_name
- LANCOMPILER 'description';
+CREATE TRUSTED PROCEDURAL LANGUAGE language-name
+ HANDLER handler_function_name;
The optional key word TRUSTED tells
whether ordinary database users that have no superuser
CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
- '$libdir/plpgsql' LANGUAGE 'C';
+ '$libdir/plpgsql' LANGUAGE C;
The command
-CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
- HANDLER plpgsql_call_handler
- LANCOMPILER 'PL/pgSQL';
+CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
+ HANDLER plpgsql_call_handler;
then defines that the previously declared call handler function
should be invoked for functions and trigger procedures where the
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.243 2001/08/10 18:57:36 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.244 2001/08/13 21:34:51 petere Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
%type OptUserList
%type OptUserElem
-%type TriggerActionTime, TriggerForSpec, PLangTrusted, opt_procedural
+%type TriggerActionTime, TriggerForSpec, opt_trusted, opt_procedural
+%type opt_lancompiler
%type OptConstrFromTable
*
*****************************************************************************/
-CreatePLangStmt: CREATE PLangTrusted opt_procedural LANGUAGE Sconst
- HANDLER func_name LANCOMPILER Sconst
+CreatePLangStmt: CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
+ HANDLER func_name opt_lancompiler
{
CreatePLangStmt *n = makeNode(CreatePLangStmt);
n->plname = $5;
n->plhandler = $7;
- n->plcompiler = $9;
+ n->plcompiler = $8;
n->pltrusted = $2;
$$ = (Node *)n;
}
;
-PLangTrusted: TRUSTED { $$ = TRUE; }
+opt_trusted: TRUSTED { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; }
;
-DropPLangStmt: DROP opt_procedural LANGUAGE Sconst
+opt_lancompiler: LANCOMPILER Sconst { $$ = $2; }
+ | /*EMPTY*/ { $$ = ""; }
+
+DropPLangStmt: DROP opt_procedural LANGUAGE ColId_or_Sconst
{
DropPLangStmt *n = makeNode(DropPLangStmt);
n->plname = $4;
*****************************************************************************/
ProcedureStmt: CREATE FUNCTION func_name func_args
- RETURNS func_return AS func_as LANGUAGE Sconst opt_with
+ RETURNS func_return AS func_as LANGUAGE ColId_or_Sconst opt_with
{
ProcedureStmt *n = makeNode(ProcedureStmt);
n->funcname = $3;
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.28 2001/06/18 21:40:06 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.29 2001/08/13 21:34:54 petere Exp $
#
#-------------------------------------------------------------------------
shift
done
-if [ "$usage" ]; then
+if [ -n "$usage" ]; then
echo "$CMDNAME installs a procedural language into a PostgreSQL database."
echo
echo "Usage:"
# List option
# ----------
if [ "$list" ]; then
- sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't';"
+ sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\" FROM pg_language WHERE lanispl = TRUE;"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
# ----------
# Check if supported and set related values
# ----------
+
+langname=`echo "$langname" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+
case "$langname" in
plpgsql)
- lancomp="PL/pgSQL"
trusted="TRUSTED "
handler="plpgsql_call_handler"
object="plpgsql"
;;
pltcl)
- lancomp="PL/Tcl"
trusted="TRUSTED "
handler="pltcl_call_handler"
object="pltcl"
;;
pltclu)
- lancomp="PL/Tcl (untrusted)"
trusted=""
handler="pltclu_call_handler"
object="pltcl"
;;
plperl)
- lancomp="PL/Perl"
trusted="TRUSTED "
handler="plperl_call_handler"
object="plperl"
;;
plperlu)
- lancomp="PL/Perl (untrusted)"
trusted=""
handler="plperl_call_handler"
object="plperl"
;;
plpython)
- lancomp="PL/Python"
trusted="TRUSTED "
handler="plpython_call_handler"
object="plpython"
;;
*)
- echo "$CMDNAME: unsupported language '$langname'" 1>&2
- echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', 'plperl', and 'plpython'." 1>&2
+ echo "$CMDNAME: unsupported language \"$langname\"" 1>&2
+ echo "Supported languages are plpgsql, pltcl, pltclu, plperl, plperlu, and plpython." 1>&2
exit 1
;;
esac
echo "$CMDNAME: external error" 1>&2
exit 1
fi
-if [ "$res" ]; then
- echo "$CMDNAME: '$langname' is already installed in database $dbname" 1>&2
+if [ -n "$res" ]; then
+ echo "$CMDNAME: language \"$langname\" is already installed in database $dbname" 1>&2
# separate exit status for "already installed"
exit 2
fi
# ----------
-# Check that there is no function named as the call handler
+# Check whether the call handler exists
# ----------
-sqlcmd="SELECT oid FROM pg_proc WHERE proname = '$handler';"
+sqlcmd="SELECT oid FROM pg_proc WHERE proname = '$handler' AND prorettype = 0 AND pronargs = 0;"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
res=`$PSQL "$sqlcmd"`
-if [ ! -z "$res" ]; then
- echo "$CMDNAME: A function named '$handler' already exists. Installation aborted." 1>&2
- exit 1
+if [ -n "$res" ]; then
+ handlerexists=yes
+else
+ handlerexists=no
fi
# ----------
# Create the call handler and the language
# ----------
-sqlcmd="CREATE FUNCTION $handler () RETURNS OPAQUE AS '$PGLIB/${object}' LANGUAGE 'C';"
-if [ "$showsql" = yes ]; then
- echo "$sqlcmd"
-fi
-$PSQL "$sqlcmd"
-if [ $? -ne 0 ]; then
- echo "$CMDNAME: language installation failed" 1>&2
- exit 1
+if [ "$handlerexists" = no ]; then
+ sqlcmd="CREATE FUNCTION \"$handler\" () RETURNS OPAQUE AS '$PGLIB/${object}' LANGUAGE C;"
+ if [ "$showsql" = yes ]; then
+ echo "$sqlcmd"
+ fi
+ $PSQL "$sqlcmd"
+ if [ $? -ne 0 ]; then
+ echo "$CMDNAME: language installation failed" 1>&2
+ exit 1
+ fi
fi
-sqlcmd="CREATE ${trusted}PROCEDURAL LANGUAGE '$langname' HANDLER $handler LANCOMPILER '$lancomp';"
+sqlcmd="CREATE ${trusted}LANGUAGE \"$langname\" HANDLER \"$handler\";"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.15 2001/05/12 01:30:30 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.16 2001/08/13 21:34:54 petere Exp $
#
#-------------------------------------------------------------------------
if [ "$list" ]; then
- sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'"
+ sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\" FROM pg_language WHERE lanispl = TRUE"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
read langname
fi
-# ----------
-# Check if supported and set related values
-# ----------
-case "$langname" in
- plpgsql)
- lancomp="PL/pgSQL"
- handler="plpgsql_call_handler"
- ;;
- pltcl)
- lancomp="PL/Tcl"
- handler="pltcl_call_handler"
- ;;
- pltclu)
- lancomp="PL/Tcl (untrusted)"
- handler="pltclu_call_handler"
- ;;
- plperl)
- lancomp="PL/Perl"
- handler="plperl_call_handler"
- ;;
- plpython)
- lancomp="PL/Python"
- handler="plpython_call_handler"
- ;;
- *)
- echo "$CMDNAME: unsupported language '$langname'" 1>&2
- echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', 'plperl', and 'plpython'." 1>&2
- exit 1
- ;;
-esac
-
-
PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c"
# ----------
-# Make sure the language is installed
+# Make sure the language is installed and find the oid of the handler function
# ----------
-sqlcmd="SELECT oid FROM pg_language WHERE lanname = '$langname';"
+sqlcmd="SELECT lanplcallfoid FROM pg_language WHERE lanname = '$langname' AND lanispl;"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
-res=`$PSQL "$sqlcmd"`
+lanplcallfoid=`$PSQL "$sqlcmd"`
if [ $? -ne 0 ]; then
echo "$CMDNAME: external error" 1>&2
exit 1
fi
-if [ -z "$res" ]; then
- echo "$CMDNAME: '$langname' is not installed in database $dbname" 1>&2
+if [ -z "$lanplcallfoid" ]; then
+ echo "$CMDNAME: language \"$langname\" is not installed in database $dbname" 1>&2
exit 1
fi
fi
if [ "$res" -ne 0 ]; then
echo "$CMDNAME: There are $res functions/trigger procedures declared in language" 1>&2
- echo "$lancomp. Language not removed." 1>&2
+ echo "$langname. Language not removed." 1>&2
exit 1
fi
# ----------
-# Drop the language and the call handler function
+# Check that the handler function isn't used by some other language
# ----------
-sqlcmd="DROP PROCEDURAL LANGUAGE '$langname';"
+sqlcmd="SELECT count(*) FROM pg_language WHERE lanplcallfoid = $lanplcallfoid AND lanname <> '$langname';"
+if [ "$showsql" = yes ]; then
+ echo "$sqlcmd"
+fi
+res=`$PSQL "$sqlcmd"`
+if [ $? -ne 0 ]; then
+ echo "$CMDNAME: external error" 1>&2
+ exit 1
+fi
+if [ "$res" -eq 0 ]; then
+ keephandler=no
+else
+ keephandler=yes
+fi
+
+# ----------
+# Drop the language
+# ----------
+sqlcmd="DROP LANGUAGE \"$langname\";"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
exit 1
fi
-sqlcmd="DROP FUNCTION $handler();"
+# ----------
+# Drop the call handler
+# ----------
+if [ "$keephandler" = yes ]; then
+ exit 0
+fi
+
+sqlcmd="SELECT proname FROM pg_proc WHERE oid = $lanplcallfoid;"
+if [ "$showsql" = yes ]; then
+ echo "$sqlcmd"
+fi
+handler=`$PSQL "$sqlcmd"`
+if [ $? -ne 0 ]; then
+ echo "$CMDNAME: external error" 1>&2
+ exit 1
+fi
+
+sqlcmd="DROP FUNCTION \"$handler\" ();"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi