mirror of https://github.com/postgres/postgres
This adds a new object type "procedure" that is similar to a function but does not have a return type and is invoked by the new CALL statement instead of SELECT or similar. This implementation is aligned with the SQL standard and compatible with or similar to other SQL implementations. This commit adds new commands CALL, CREATE/ALTER/DROP PROCEDURE, as well as ALTER/DROP ROUTINE that can refer to either a function or a procedure (or an aggregate function, as an extension to SQL). There is also support for procedures in various utility commands such as COMMENT and GRANT, as well as support in pg_dump and psql. Support for defining procedures is available in all the languages supplied by the core distribution. While this commit is mainly syntax sugar around existing functionality, future features will rely on having procedures as a separate object type. Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>pull/31/head^2
parent
1761653bbb
commit
e4128ee767
@ -0,0 +1,281 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/alter_procedure.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="sql-alterprocedure"> |
||||
<indexterm zone="sql-alterprocedure"> |
||||
<primary>ALTER PROCEDURE</primary> |
||||
</indexterm> |
||||
|
||||
<refmeta> |
||||
<refentrytitle>ALTER PROCEDURE</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>ALTER PROCEDURE</refname> |
||||
<refpurpose>change the definition of a procedure</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
ALTER PROCEDURE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
<replaceable class="parameter">action</replaceable> [ ... ] [ RESTRICT ] |
||||
ALTER PROCEDURE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
RENAME TO <replaceable>new_name</replaceable> |
||||
ALTER PROCEDURE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER } |
||||
ALTER PROCEDURE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
SET SCHEMA <replaceable>new_schema</replaceable> |
||||
ALTER PROCEDURE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
DEPENDS ON EXTENSION <replaceable>extension_name</replaceable> |
||||
|
||||
<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase> |
||||
|
||||
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER |
||||
SET <replaceable class="parameter">configuration_parameter</replaceable> { TO | = } { <replaceable class="parameter">value</replaceable> | DEFAULT } |
||||
SET <replaceable class="parameter">configuration_parameter</replaceable> FROM CURRENT |
||||
RESET <replaceable class="parameter">configuration_parameter</replaceable> |
||||
RESET ALL |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>ALTER PROCEDURE</command> changes the definition of a |
||||
procedure. |
||||
</para> |
||||
|
||||
<para> |
||||
You must own the procedure to use <command>ALTER PROCEDURE</command>. |
||||
To change a procedure's schema, you must also have <literal>CREATE</literal> |
||||
privilege on the new schema. |
||||
To alter the owner, you must also be a direct or indirect member of the new |
||||
owning role, and that role must have <literal>CREATE</literal> privilege on |
||||
the procedure's schema. (These restrictions enforce that altering the owner |
||||
doesn't do anything you couldn't do by dropping and recreating the procedure. |
||||
However, a superuser can alter ownership of any procedure anyway.) |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name (optionally schema-qualified) of an existing procedure. If no |
||||
argument list is specified, the name must be unique in its schema. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argmode</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The mode of an argument: <literal>IN</literal> or <literal>VARIADIC</literal>. |
||||
If omitted, the default is <literal>IN</literal>. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argname</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The name of an argument. |
||||
Note that <command>ALTER PROCEDURE</command> does not actually pay |
||||
any attention to argument names, since only the argument data |
||||
types are needed to determine the procedure's identity. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argtype</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The data type(s) of the procedure's arguments (optionally |
||||
schema-qualified), if any. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">new_name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The new name of the procedure. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">new_owner</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The new owner of the procedure. Note that if the procedure is |
||||
marked <literal>SECURITY DEFINER</literal>, it will subsequently |
||||
execute as the new owner. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">new_schema</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The new schema for the procedure. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">extension_name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name of the extension that the procedure is to depend on. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal><optional> EXTERNAL </optional> SECURITY INVOKER</literal></term> |
||||
<term><literal><optional> EXTERNAL </optional> SECURITY DEFINER</literal></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
Change whether the procedure is a security definer or not. The |
||||
key word <literal>EXTERNAL</literal> is ignored for SQL |
||||
conformance. See <xref linkend="sql-createprocedure"/> for more information about |
||||
this capability. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable>configuration_parameter</replaceable></term> |
||||
<term><replaceable>value</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
Add or change the assignment to be made to a configuration parameter |
||||
when the procedure is called. If |
||||
<replaceable>value</replaceable> is <literal>DEFAULT</literal> |
||||
or, equivalently, <literal>RESET</literal> is used, the procedure-local |
||||
setting is removed, so that the procedure executes with the value |
||||
present in its environment. Use <literal>RESET |
||||
ALL</literal> to clear all procedure-local settings. |
||||
<literal>SET FROM CURRENT</literal> saves the value of the parameter that |
||||
is current when <command>ALTER PROCEDURE</command> is executed as the value |
||||
to be applied when the procedure is entered. |
||||
</para> |
||||
|
||||
<para> |
||||
See <xref linkend="sql-set"/> and |
||||
<xref linkend="runtime-config"/> |
||||
for more information about allowed parameter names and values. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>RESTRICT</literal></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
Ignored for conformance with the SQL standard. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
To rename the procedure <literal>insert_data</literal> with two arguments |
||||
of type <type>integer</type> to <literal>insert_record</literal>: |
||||
<programlisting> |
||||
ALTER PROCEDURE insert_data(integer, integer) RENAME TO insert_record; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
To change the owner of the procedure <literal>insert_data</literal> with |
||||
two arguments of type <type>integer</type> to <literal>joe</literal>: |
||||
<programlisting> |
||||
ALTER PROCEDURE insert_data(integer, integer) OWNER TO joe; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
To change the schema of the procedure <literal>insert_data</literal> with |
||||
two arguments of type <type>integer</type> |
||||
to <literal>accounting</literal>: |
||||
<programlisting> |
||||
ALTER PROCEDURE insert_data(integer, integer) SET SCHEMA accounting; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
To mark the procedure <literal>insert_data(integer, integer)</literal> as |
||||
being dependent on the extension <literal>myext</literal>: |
||||
<programlisting> |
||||
ALTER PROCEDURE insert_data(integer, integer) DEPENDS ON EXTENSION myext; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
To adjust the search path that is automatically set for a procedure: |
||||
<programlisting> |
||||
ALTER PROCEDURE check_password(text) SET search_path = admin, pg_temp; |
||||
</programlisting> |
||||
</para> |
||||
|
||||
<para> |
||||
To disable automatic setting of <varname>search_path</varname> for a procedure: |
||||
<programlisting> |
||||
ALTER PROCEDURE check_password(text) RESET search_path; |
||||
</programlisting> |
||||
The procedure will now execute with whatever search path is used by its |
||||
caller. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
This statement is partially compatible with the <command>ALTER |
||||
PROCEDURE</command> statement in the SQL standard. The standard allows more |
||||
properties of a procedure to be modified, but does not provide the |
||||
ability to rename a procedure, make a procedure a security definer, |
||||
attach configuration parameter values to a procedure, |
||||
or change the owner, schema, or volatility of a procedure. The standard also |
||||
requires the <literal>RESTRICT</literal> key word, which is optional in |
||||
<productname>PostgreSQL</productname>. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createprocedure"/></member> |
||||
<member><xref linkend="sql-dropprocedure"/></member> |
||||
<member><xref linkend="sql-alterfunction"/></member> |
||||
<member><xref linkend="sql-alterroutine"/></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
</refentry> |
@ -0,0 +1,102 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/alter_routine.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="sql-alterroutine"> |
||||
<indexterm zone="sql-alterroutine"> |
||||
<primary>ALTER ROUTINE</primary> |
||||
</indexterm> |
||||
|
||||
<refmeta> |
||||
<refentrytitle>ALTER ROUTINE</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>ALTER ROUTINE</refname> |
||||
<refpurpose>change the definition of a routine</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
ALTER ROUTINE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
<replaceable class="parameter">action</replaceable> [ ... ] [ RESTRICT ] |
||||
ALTER ROUTINE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
RENAME TO <replaceable>new_name</replaceable> |
||||
ALTER ROUTINE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER } |
||||
ALTER ROUTINE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
SET SCHEMA <replaceable>new_schema</replaceable> |
||||
ALTER ROUTINE <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
||||
DEPENDS ON EXTENSION <replaceable>extension_name</replaceable> |
||||
|
||||
<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase> |
||||
|
||||
IMMUTABLE | STABLE | VOLATILE | [ NOT ] LEAKPROOF |
||||
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER |
||||
PARALLEL { UNSAFE | RESTRICTED | SAFE } |
||||
COST <replaceable class="parameter">execution_cost</replaceable> |
||||
ROWS <replaceable class="parameter">result_rows</replaceable> |
||||
SET <replaceable class="parameter">configuration_parameter</replaceable> { TO | = } { <replaceable class="parameter">value</replaceable> | DEFAULT } |
||||
SET <replaceable class="parameter">configuration_parameter</replaceable> FROM CURRENT |
||||
RESET <replaceable class="parameter">configuration_parameter</replaceable> |
||||
RESET ALL |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>ALTER ROUTINE</command> changes the definition of a routine, which |
||||
can be an aggregate function, a normal function, or a procedure. See |
||||
under <xref linkend="sql-alteraggregate"/>, <xref linkend="sql-alterfunction"/>, |
||||
and <xref linkend="sql-alterprocedure"/> for the description of the |
||||
parameters, more examples, and further details. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
To rename the routine <literal>foo</literal> for type |
||||
<type>integer</type> to <literal>foobar</literal>: |
||||
<programlisting> |
||||
ALTER ROUTINE foo(integer) RENAME TO foobar; |
||||
</programlisting> |
||||
This command will work independent of whether <literal>foo</literal> is an |
||||
aggregate, function, or procedure. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
This statement is partially compatible with the <command>ALTER |
||||
ROUTINE</command> statement in the SQL standard. See |
||||
under <xref linkend="sql-alterfunction"/> |
||||
and <xref linkend="sql-alterprocedure"/> for more details. Allowing |
||||
routine names to refer to aggregate functions is |
||||
a <productname>PostgreSQL</productname> extension. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-alteraggregate"/></member> |
||||
<member><xref linkend="sql-alterfunction"/></member> |
||||
<member><xref linkend="sql-alterprocedure"/></member> |
||||
<member><xref linkend="sql-droproutine"/></member> |
||||
</simplelist> |
||||
|
||||
<para> |
||||
Note that there is no <literal>CREATE ROUTINE</literal> command. |
||||
</para> |
||||
</refsect1> |
||||
</refentry> |
@ -0,0 +1,97 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/call.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="sql-call"> |
||||
<indexterm zone="sql-call"> |
||||
<primary>CALL</primary> |
||||
</indexterm> |
||||
|
||||
<refmeta> |
||||
<refentrytitle>CALL</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>CALL</refname> |
||||
<refpurpose>invoke a procedure</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
CALL <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> ] [ , ...] ) |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>CALL</command> executes a procedure. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name (optionally schema-qualified) of the procedure. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argument</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
An argument for the procedure call. |
||||
See <xref linkend="sql-syntax-calling-funcs"/> for the full details on |
||||
function and procedure call syntax, including use of named parameters. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Notes</title> |
||||
|
||||
<para> |
||||
The user must have <literal>EXECUTE</literal> privilege on the procedure in |
||||
order to be allowed to invoke it. |
||||
</para> |
||||
|
||||
<para> |
||||
To call a function (not a procedure), use <command>SELECT</command> instead. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Examples</title> |
||||
<programlisting> |
||||
CALL do_db_maintenance(); |
||||
</programlisting> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
<command>CALL</command> conforms to the SQL standard. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createprocedure"/></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
</refentry> |
@ -0,0 +1,341 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/create_procedure.sgml |
||||
--> |
||||
|
||||
<refentry id="sql-createprocedure"> |
||||
<indexterm zone="sql-createprocedure"> |
||||
<primary>CREATE PROCEDURE</primary> |
||||
</indexterm> |
||||
|
||||
<refmeta> |
||||
<refentrytitle>CREATE PROCEDURE</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>CREATE PROCEDURE</refname> |
||||
<refpurpose>define a new procedure</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
CREATE [ OR REPLACE ] PROCEDURE |
||||
<replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [ { DEFAULT | = } <replaceable class="parameter">default_expr</replaceable> ] [, ...] ] ) |
||||
{ LANGUAGE <replaceable class="parameter">lang_name</replaceable> |
||||
| TRANSFORM { FOR TYPE <replaceable class="parameter">type_name</replaceable> } [, ... ] |
||||
| [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER |
||||
| SET <replaceable class="parameter">configuration_parameter</replaceable> { TO <replaceable class="parameter">value</replaceable> | = <replaceable class="parameter">value</replaceable> | FROM CURRENT } |
||||
| AS '<replaceable class="parameter">definition</replaceable>' |
||||
| AS '<replaceable class="parameter">obj_file</replaceable>', '<replaceable class="parameter">link_symbol</replaceable>' |
||||
} ... |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1 id="sql-createprocedure-description"> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>CREATE PROCEDURE</command> defines a new procedure. |
||||
<command>CREATE OR REPLACE PROCEDURE</command> will either create a |
||||
new procedure, or replace an existing definition. |
||||
To be able to define a procedure, the user must have the |
||||
<literal>USAGE</literal> privilege on the language. |
||||
</para> |
||||
|
||||
<para> |
||||
If a schema name is included, then the procedure is created in the |
||||
specified schema. Otherwise it is created in the current schema. |
||||
The name of the new procedure must not match any existing procedure or function |
||||
with the same input argument types in the same schema. However, |
||||
procedures and functions of different argument types can share a name (this is |
||||
called <firstterm>overloading</firstterm>). |
||||
</para> |
||||
|
||||
<para> |
||||
To replace the current definition of an existing procedure, use |
||||
<command>CREATE OR REPLACE PROCEDURE</command>. It is not possible |
||||
to change the name or argument types of a procedure this way (if you |
||||
tried, you would actually be creating a new, distinct procedure). |
||||
</para> |
||||
|
||||
<para> |
||||
When <command>CREATE OR REPLACE PROCEDURE</command> is used to replace an |
||||
existing procedure, the ownership and permissions of the procedure |
||||
do not change. All other procedure properties are assigned the |
||||
values specified or implied in the command. You must own the procedure |
||||
to replace it (this includes being a member of the owning role). |
||||
</para> |
||||
|
||||
<para> |
||||
The user that creates the procedure becomes the owner of the procedure. |
||||
</para> |
||||
|
||||
<para> |
||||
To be able to create a procedure, you must have <literal>USAGE</literal> |
||||
privilege on the argument types. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The name (optionally schema-qualified) of the procedure to create. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argmode</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The mode of an argument: <literal>IN</literal> or <literal>VARIADIC</literal>. |
||||
If omitted, the default is <literal>IN</literal>. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argname</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The name of an argument. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argtype</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The data type(s) of the procedure's arguments (optionally |
||||
schema-qualified), if any. The argument types can be base, composite, |
||||
or domain types, or can reference the type of a table column. |
||||
</para> |
||||
<para> |
||||
Depending on the implementation language it might also be allowed |
||||
to specify <quote>pseudo-types</quote> such as <type>cstring</type>. |
||||
Pseudo-types indicate that the actual argument type is either |
||||
incompletely specified, or outside the set of ordinary SQL data types. |
||||
</para> |
||||
<para> |
||||
The type of a column is referenced by writing |
||||
<literal><replaceable |
||||
class="parameter">table_name</replaceable>.<replaceable |
||||
class="parameter">column_name</replaceable>%TYPE</literal>. |
||||
Using this feature can sometimes help make a procedure independent of |
||||
changes to the definition of a table. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">default_expr</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
An expression to be used as default value if the parameter is |
||||
not specified. The expression has to be coercible to the |
||||
argument type of the parameter. |
||||
All input parameters following a |
||||
parameter with a default value must have default values as well. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">lang_name</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The name of the language that the procedure is implemented in. |
||||
It can be <literal>sql</literal>, <literal>c</literal>, |
||||
<literal>internal</literal>, or the name of a user-defined |
||||
procedural language, e.g. <literal>plpgsql</literal>. Enclosing the |
||||
name in single quotes is deprecated and requires matching case. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>TRANSFORM { FOR TYPE <replaceable class="parameter">type_name</replaceable> } [, ... ] }</literal></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
Lists which transforms a call to the procedure should apply. Transforms |
||||
convert between SQL types and language-specific data types; |
||||
see <xref linkend="sql-createtransform"/>. Procedural language |
||||
implementations usually have hardcoded knowledge of the built-in types, |
||||
so those don't need to be listed here. If a procedural language |
||||
implementation does not know how to handle a type and no transform is |
||||
supplied, it will fall back to a default behavior for converting data |
||||
types, but this depends on the implementation. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal><optional>EXTERNAL</optional> SECURITY INVOKER</literal></term> |
||||
<term><literal><optional>EXTERNAL</optional> SECURITY DEFINER</literal></term> |
||||
|
||||
<listitem> |
||||
<para><literal>SECURITY INVOKER</literal> indicates that the procedure |
||||
is to be executed with the privileges of the user that calls it. |
||||
That is the default. <literal>SECURITY DEFINER</literal> |
||||
specifies that the procedure is to be executed with the |
||||
privileges of the user that owns it. |
||||
</para> |
||||
|
||||
<para> |
||||
The key word <literal>EXTERNAL</literal> is allowed for SQL |
||||
conformance, but it is optional since, unlike in SQL, this feature |
||||
applies to all procedures not only external ones. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable>configuration_parameter</replaceable></term> |
||||
<term><replaceable>value</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The <literal>SET</literal> clause causes the specified configuration |
||||
parameter to be set to the specified value when the procedure is |
||||
entered, and then restored to its prior value when the procedure exits. |
||||
<literal>SET FROM CURRENT</literal> saves the value of the parameter that |
||||
is current when <command>CREATE PROCEDURE</command> is executed as the value |
||||
to be applied when the procedure is entered. |
||||
</para> |
||||
|
||||
<para> |
||||
If a <literal>SET</literal> clause is attached to a procedure, then |
||||
the effects of a <command>SET LOCAL</command> command executed inside the |
||||
procedure for the same variable are restricted to the procedure: the |
||||
configuration parameter's prior value is still restored at procedure exit. |
||||
However, an ordinary |
||||
<command>SET</command> command (without <literal>LOCAL</literal>) overrides the |
||||
<literal>SET</literal> clause, much as it would do for a previous <command>SET |
||||
LOCAL</command> command: the effects of such a command will persist after |
||||
procedure exit, unless the current transaction is rolled back. |
||||
</para> |
||||
|
||||
<para> |
||||
See <xref linkend="sql-set"/> and |
||||
<xref linkend="runtime-config"/> |
||||
for more information about allowed parameter names and values. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">definition</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
A string constant defining the procedure; the meaning depends on the |
||||
language. It can be an internal procedure name, the path to an |
||||
object file, an SQL command, or text in a procedural language. |
||||
</para> |
||||
|
||||
<para> |
||||
It is often helpful to use dollar quoting (see <xref |
||||
linkend="sql-syntax-dollar-quoting"/>) to write the procedure definition |
||||
string, rather than the normal single quote syntax. Without dollar |
||||
quoting, any single quotes or backslashes in the procedure definition must |
||||
be escaped by doubling them. |
||||
</para> |
||||
|
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal><replaceable class="parameter">obj_file</replaceable>, <replaceable class="parameter">link_symbol</replaceable></literal></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
This form of the <literal>AS</literal> clause is used for |
||||
dynamically loadable C language procedures when the procedure name |
||||
in the C language source code is not the same as the name of |
||||
the SQL procedure. The string <replaceable |
||||
class="parameter">obj_file</replaceable> is the name of the shared |
||||
library file containing the compiled C procedure, and is interpreted |
||||
as for the <xref linkend="sql-load"/> command. The string |
||||
<replaceable class="parameter">link_symbol</replaceable> is the |
||||
procedure's link symbol, that is, the name of the procedure in the C |
||||
language source code. If the link symbol is omitted, it is assumed |
||||
to be the same as the name of the SQL procedure being defined. |
||||
</para> |
||||
|
||||
<para> |
||||
When repeated <command>CREATE PROCEDURE</command> calls refer to |
||||
the same object file, the file is only loaded once per session. |
||||
To unload and |
||||
reload the file (perhaps during development), start a new session. |
||||
</para> |
||||
|
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-createprocedure-notes"> |
||||
<title>Notes</title> |
||||
|
||||
<para> |
||||
See <xref linkend="sql-createfunction"/> for more details on function |
||||
creation that also apply to procedures. |
||||
</para> |
||||
|
||||
<para> |
||||
Use <xref linkend="sql-call"/> to execute a procedure. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-createprocedure-examples"> |
||||
<title>Examples</title> |
||||
|
||||
<programlisting> |
||||
CREATE PROCEDURE insert_data(a integer, b integer) |
||||
LANGUAGE SQL |
||||
AS $$ |
||||
INSERT INTO tbl VALUES (a); |
||||
INSERT INTO tbl VALUES (b); |
||||
$$; |
||||
|
||||
CALL insert_data(1, 2); |
||||
</programlisting> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-createprocedure-compat"> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
A <command>CREATE PROCEDURE</command> command is defined in the SQL |
||||
standard. The <productname>PostgreSQL</productname> version is similar but |
||||
not fully compatible. For details see |
||||
also <xref linkend="sql-createfunction"/>. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-alterprocedure"/></member> |
||||
<member><xref linkend="sql-dropprocedure"/></member> |
||||
<member><xref linkend="sql-call"/></member> |
||||
<member><xref linkend="sql-createfunction"/></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
@ -0,0 +1,162 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/drop_procedure.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="sql-dropprocedure"> |
||||
<indexterm zone="sql-dropprocedure"> |
||||
<primary>DROP PROCEDURE</primary> |
||||
</indexterm> |
||||
|
||||
<refmeta> |
||||
<refentrytitle>DROP PROCEDURE</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>DROP PROCEDURE</refname> |
||||
<refpurpose>remove a procedure</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
DROP PROCEDURE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] [, ...] |
||||
[ CASCADE | RESTRICT ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>DROP PROCEDURE</command> removes the definition of an existing |
||||
procedure. To execute this command the user must be the |
||||
owner of the procedure. The argument types to the |
||||
procedure must be specified, since several different procedures |
||||
can exist with the same name and different argument lists. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>Parameters</title> |
||||
|
||||
<variablelist> |
||||
<varlistentry> |
||||
<term><literal>IF EXISTS</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Do not throw an error if the procedure does not exist. A notice is issued |
||||
in this case. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">name</replaceable></term> |
||||
<listitem> |
||||
<para> |
||||
The name (optionally schema-qualified) of an existing procedure. If no |
||||
argument list is specified, the name must be unique in its schema. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argmode</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The mode of an argument: <literal>IN</literal> or <literal>VARIADIC</literal>. |
||||
If omitted, the default is <literal>IN</literal>. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argname</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The name of an argument. |
||||
Note that <command>DROP PROCEDURE</command> does not actually pay |
||||
any attention to argument names, since only the argument data |
||||
types are needed to determine the procedure's identity. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><replaceable class="parameter">argtype</replaceable></term> |
||||
|
||||
<listitem> |
||||
<para> |
||||
The data type(s) of the procedure's arguments (optionally |
||||
schema-qualified), if any. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>CASCADE</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Automatically drop objects that depend on the procedure, |
||||
and in turn all objects that depend on those objects |
||||
(see <xref linkend="ddl-depend"/>). |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
|
||||
<varlistentry> |
||||
<term><literal>RESTRICT</literal></term> |
||||
<listitem> |
||||
<para> |
||||
Refuse to drop the procedure if any objects depend on it. This |
||||
is the default. |
||||
</para> |
||||
</listitem> |
||||
</varlistentry> |
||||
</variablelist> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-dropprocedure-examples"> |
||||
<title>Examples</title> |
||||
|
||||
<programlisting> |
||||
DROP PROCEDURE do_db_maintenance(); |
||||
</programlisting> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-dropprocedure-compatibility"> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
This command conforms to the SQL standard, with |
||||
these <productname>PostgreSQL</productname> extensions: |
||||
<itemizedlist> |
||||
<listitem> |
||||
<para>The standard only allows one procedure to be dropped per command.</para> |
||||
</listitem> |
||||
<listitem> |
||||
<para>The <literal>IF EXISTS</literal> option</para> |
||||
</listitem> |
||||
<listitem> |
||||
<para>The ability to specify argument modes and names</para> |
||||
</listitem> |
||||
</itemizedlist> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-createprocedure"/></member> |
||||
<member><xref linkend="sql-alterprocedure"/></member> |
||||
<member><xref linkend="sql-dropfunction"/></member> |
||||
<member><xref linkend="sql-droproutine"/></member> |
||||
</simplelist> |
||||
</refsect1> |
||||
|
||||
</refentry> |
@ -0,0 +1,94 @@ |
||||
<!-- |
||||
doc/src/sgml/ref/drop_routine.sgml |
||||
PostgreSQL documentation |
||||
--> |
||||
|
||||
<refentry id="sql-droproutine"> |
||||
<indexterm zone="sql-droproutine"> |
||||
<primary>DROP ROUTINE</primary> |
||||
</indexterm> |
||||
|
||||
<refmeta> |
||||
<refentrytitle>DROP ROUTINE</refentrytitle> |
||||
<manvolnum>7</manvolnum> |
||||
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
||||
</refmeta> |
||||
|
||||
<refnamediv> |
||||
<refname>DROP ROUTINE</refname> |
||||
<refpurpose>remove a routine</refpurpose> |
||||
</refnamediv> |
||||
|
||||
<refsynopsisdiv> |
||||
<synopsis> |
||||
DROP ROUTINE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] [, ...] |
||||
[ CASCADE | RESTRICT ] |
||||
</synopsis> |
||||
</refsynopsisdiv> |
||||
|
||||
<refsect1> |
||||
<title>Description</title> |
||||
|
||||
<para> |
||||
<command>DROP ROUTINE</command> removes the definition of an existing |
||||
routine, which can be an aggregate function, a normal function, or a |
||||
procedure. See |
||||
under <xref linkend="sql-dropaggregate"/>, <xref linkend="sql-dropfunction"/>, |
||||
and <xref linkend="sql-dropprocedure"/> for the description of the |
||||
parameters, more examples, and further details. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-droproutine-examples"> |
||||
<title>Examples</title> |
||||
|
||||
<para> |
||||
To drop the routine <literal>foo</literal> for type |
||||
<type>integer</type>: |
||||
<programlisting> |
||||
DROP ROUTINE foo(integer); |
||||
</programlisting> |
||||
This command will work independent of whether <literal>foo</literal> is an |
||||
aggregate, function, or procedure. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1 id="sql-droproutine-compatibility"> |
||||
<title>Compatibility</title> |
||||
|
||||
<para> |
||||
This command conforms to the SQL standard, with |
||||
these <productname>PostgreSQL</productname> extensions: |
||||
<itemizedlist> |
||||
<listitem> |
||||
<para>The standard only allows one routine to be dropped per command.</para> |
||||
</listitem> |
||||
<listitem> |
||||
<para>The <literal>IF EXISTS</literal> option</para> |
||||
</listitem> |
||||
<listitem> |
||||
<para>The ability to specify argument modes and names</para> |
||||
</listitem> |
||||
<listitem> |
||||
<para>Aggregate functions are an extension.</para> |
||||
</listitem> |
||||
</itemizedlist> |
||||
</para> |
||||
</refsect1> |
||||
|
||||
<refsect1> |
||||
<title>See Also</title> |
||||
|
||||
<simplelist type="inline"> |
||||
<member><xref linkend="sql-dropaggregate"/></member> |
||||
<member><xref linkend="sql-dropfunction"/></member> |
||||
<member><xref linkend="sql-dropprocedure"/></member> |
||||
<member><xref linkend="sql-alterroutine"/></member> |
||||
</simplelist> |
||||
|
||||
<para> |
||||
Note that there is no <literal>CREATE ROUTINE</literal> command. |
||||
</para> |
||||
</refsect1> |
||||
|
||||
</refentry> |
@ -0,0 +1,29 @@ |
||||
CREATE PROCEDURE test_proc1() |
||||
LANGUAGE plperl |
||||
AS $$ |
||||
undef; |
||||
$$; |
||||
CALL test_proc1(); |
||||
CREATE PROCEDURE test_proc2() |
||||
LANGUAGE plperl |
||||
AS $$ |
||||
return 5 |
||||
$$; |
||||
CALL test_proc2(); |
||||
CREATE TABLE test1 (a int); |
||||
CREATE PROCEDURE test_proc3(x int) |
||||
LANGUAGE plperl |
||||
AS $$ |
||||
spi_exec_query("INSERT INTO test1 VALUES ($_[0])"); |
||||
$$; |
||||
CALL test_proc3(55); |
||||
SELECT * FROM test1; |
||||
a |
||||
---- |
||||
55 |
||||
(1 row) |
||||
|
||||
DROP PROCEDURE test_proc1; |
||||
DROP PROCEDURE test_proc2; |
||||
DROP PROCEDURE test_proc3; |
||||
DROP TABLE test1; |
@ -0,0 +1,36 @@ |
||||
CREATE PROCEDURE test_proc1() |
||||
LANGUAGE plperl |
||||
AS $$ |
||||
undef; |
||||
$$; |
||||
|
||||
CALL test_proc1(); |
||||
|
||||
|
||||
CREATE PROCEDURE test_proc2() |
||||
LANGUAGE plperl |
||||
AS $$ |
||||
return 5 |
||||
$$; |
||||
|
||||
CALL test_proc2(); |
||||
|
||||
|
||||
CREATE TABLE test1 (a int); |
||||
|
||||
CREATE PROCEDURE test_proc3(x int) |
||||
LANGUAGE plperl |
||||
AS $$ |
||||
spi_exec_query("INSERT INTO test1 VALUES ($_[0])"); |
||||
$$; |
||||
|
||||
CALL test_proc3(55); |
||||
|
||||
SELECT * FROM test1; |
||||
|
||||
|
||||
DROP PROCEDURE test_proc1; |
||||
DROP PROCEDURE test_proc2; |
||||
DROP PROCEDURE test_proc3; |
||||
|
||||
DROP TABLE test1; |
@ -0,0 +1,35 @@ |
||||
-- |
||||
-- Tests for procedures / CALL syntax |
||||
-- |
||||
CREATE PROCEDURE test_proc1() |
||||
LANGUAGE plpythonu |
||||
AS $$ |
||||
pass |
||||
$$; |
||||
CALL test_proc1(); |
||||
-- error: can't return non-None |
||||
CREATE PROCEDURE test_proc2() |
||||
LANGUAGE plpythonu |
||||
AS $$ |
||||
return 5 |
||||
$$; |
||||
CALL test_proc2(); |
||||
ERROR: PL/Python procedure did not return None |
||||
CONTEXT: PL/Python procedure "test_proc2" |
||||
CREATE TABLE test1 (a int); |
||||
CREATE PROCEDURE test_proc3(x int) |
||||
LANGUAGE plpythonu |
||||
AS $$ |
||||
plpy.execute("INSERT INTO test1 VALUES (%s)" % x) |
||||
$$; |
||||
CALL test_proc3(55); |
||||
SELECT * FROM test1; |
||||
a |
||||
---- |
||||
55 |
||||
(1 row) |
||||
|
||||
DROP PROCEDURE test_proc1; |
||||
DROP PROCEDURE test_proc2; |
||||
DROP PROCEDURE test_proc3; |
||||
DROP TABLE test1; |
@ -0,0 +1,41 @@ |
||||
-- |
||||
-- Tests for procedures / CALL syntax |
||||
-- |
||||
|
||||
CREATE PROCEDURE test_proc1() |
||||
LANGUAGE plpythonu |
||||
AS $$ |
||||
pass |
||||
$$; |
||||
|
||||
CALL test_proc1(); |
||||
|
||||
|
||||
-- error: can't return non-None |
||||
CREATE PROCEDURE test_proc2() |
||||
LANGUAGE plpythonu |
||||
AS $$ |
||||
return 5 |
||||
$$; |
||||
|
||||
CALL test_proc2(); |
||||
|
||||
|
||||
CREATE TABLE test1 (a int); |
||||
|
||||
CREATE PROCEDURE test_proc3(x int) |
||||
LANGUAGE plpythonu |
||||
AS $$ |
||||
plpy.execute("INSERT INTO test1 VALUES (%s)" % x) |
||||
$$; |
||||
|
||||
CALL test_proc3(55); |
||||
|
||||
SELECT * FROM test1; |
||||
|
||||
|
||||
DROP PROCEDURE test_proc1; |
||||
DROP PROCEDURE test_proc2; |
||||
DROP PROCEDURE test_proc3; |
||||
|
||||
DROP TABLE test1; |
@ -0,0 +1,29 @@ |
||||
CREATE PROCEDURE test_proc1() |
||||
LANGUAGE pltcl |
||||
AS $$ |
||||
unset |
||||
$$; |
||||
CALL test_proc1(); |
||||
CREATE PROCEDURE test_proc2() |
||||
LANGUAGE pltcl |
||||
AS $$ |
||||
return 5 |
||||
$$; |
||||
CALL test_proc2(); |
||||
CREATE TABLE test1 (a int); |
||||
CREATE PROCEDURE test_proc3(x int) |
||||
LANGUAGE pltcl |
||||
AS $$ |
||||
spi_exec "INSERT INTO test1 VALUES ($1)" |
||||
$$; |
||||
CALL test_proc3(55); |
||||
SELECT * FROM test1; |
||||
a |
||||
---- |
||||
55 |
||||
(1 row) |
||||
|
||||
DROP PROCEDURE test_proc1; |
||||
DROP PROCEDURE test_proc2; |
||||
DROP PROCEDURE test_proc3; |
||||
DROP TABLE test1; |
@ -0,0 +1,36 @@ |
||||
CREATE PROCEDURE test_proc1() |
||||
LANGUAGE pltcl |
||||
AS $$ |
||||
unset |
||||
$$; |
||||
|
||||
CALL test_proc1(); |
||||
|
||||
|
||||
CREATE PROCEDURE test_proc2() |
||||
LANGUAGE pltcl |
||||
AS $$ |
||||
return 5 |
||||
$$; |
||||
|
||||
CALL test_proc2(); |
||||
|
||||
|
||||
CREATE TABLE test1 (a int); |
||||
|
||||
CREATE PROCEDURE test_proc3(x int) |
||||
LANGUAGE pltcl |
||||
AS $$ |
||||
spi_exec "INSERT INTO test1 VALUES ($1)" |
||||
$$; |
||||
|
||||
CALL test_proc3(55); |
||||
|
||||
SELECT * FROM test1; |
||||
|
||||
|
||||
DROP PROCEDURE test_proc1; |
||||
DROP PROCEDURE test_proc2; |
||||
DROP PROCEDURE test_proc3; |
||||
|
||||
DROP TABLE test1; |
@ -0,0 +1,92 @@ |
||||
CALL nonexistent(); -- error |
||||
ERROR: function nonexistent() does not exist |
||||
LINE 1: CALL nonexistent(); |
||||
^ |
||||
HINT: No function matches the given name and argument types. You might need to add explicit type casts. |
||||
CALL random(); -- error |
||||
ERROR: random() is not a procedure |
||||
LINE 1: CALL random(); |
||||
^ |
||||
HINT: To call a function, use SELECT. |
||||
CREATE FUNCTION testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$; |
||||
CREATE TABLE cp_test (a int, b text); |
||||
CREATE PROCEDURE ptest1(x text) |
||||
LANGUAGE SQL |
||||
AS $$ |
||||
INSERT INTO cp_test VALUES (1, x); |
||||
$$; |
||||
SELECT ptest1('x'); -- error |
||||
ERROR: ptest1(unknown) is a procedure |
||||
LINE 1: SELECT ptest1('x'); |
||||
^ |
||||
HINT: To call a procedure, use CALL. |
||||
CALL ptest1('a'); -- ok |
||||
\df ptest1 |
||||
List of functions |
||||
Schema | Name | Result data type | Argument data types | Type |
||||
--------+--------+------------------+---------------------+------ |
||||
public | ptest1 | | x text | proc |
||||
(1 row) |
||||
|
||||
SELECT * FROM cp_test ORDER BY a; |
||||
a | b |
||||
---+--- |
||||
1 | a |
||||
(1 row) |
||||
|
||||
CREATE PROCEDURE ptest2() |
||||
LANGUAGE SQL |
||||
AS $$ |
||||
SELECT 5; |
||||
$$; |
||||
CALL ptest2(); |
||||
-- various error cases |
||||
CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; |
||||
ERROR: invalid attribute in procedure definition |
||||
LINE 1: CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT I... |
||||
^ |
||||
CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; |
||||
ERROR: invalid attribute in procedure definition |
||||
LINE 1: CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT I... |
||||
^ |
||||
CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; |
||||
ERROR: procedures cannot have OUT parameters |
||||
ALTER PROCEDURE ptest1(text) STRICT; |
||||
ERROR: invalid attribute in procedure definition |
||||
LINE 1: ALTER PROCEDURE ptest1(text) STRICT; |
||||
^ |
||||
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function |
||||
ERROR: ptest1(text) is not a function |
||||
ALTER PROCEDURE testfunc1(int) VOLATILE; -- error: not a procedure |
||||
ERROR: testfunc1(integer) is not a procedure |
||||
ALTER PROCEDURE nonexistent() VOLATILE; |
||||
ERROR: procedure nonexistent() does not exist |
||||
DROP FUNCTION ptest1(text); -- error: not a function |
||||
ERROR: ptest1(text) is not a function |
||||
DROP PROCEDURE testfunc1(int); -- error: not a procedure |
||||
ERROR: testfunc1(integer) is not a procedure |
||||
DROP PROCEDURE nonexistent(); |
||||
ERROR: procedure nonexistent() does not exist |
||||
-- privileges |
||||
CREATE USER regress_user1; |
||||
GRANT INSERT ON cp_test TO regress_user1; |
||||
REVOKE EXECUTE ON PROCEDURE ptest1(text) FROM PUBLIC; |
||||
SET ROLE regress_user1; |
||||
CALL ptest1('a'); -- error |
||||
ERROR: permission denied for function ptest1 |
||||
RESET ROLE; |
||||
GRANT EXECUTE ON PROCEDURE ptest1(text) TO regress_user1; |
||||
SET ROLE regress_user1; |
||||
CALL ptest1('a'); -- ok |
||||
RESET ROLE; |
||||
-- ROUTINE syntax |
||||
ALTER ROUTINE testfunc1(int) RENAME TO testfunc1a; |
||||
ALTER ROUTINE testfunc1a RENAME TO testfunc1; |
||||
ALTER ROUTINE ptest1(text) RENAME TO ptest1a; |
||||
ALTER ROUTINE ptest1a RENAME TO ptest1; |
||||
DROP ROUTINE testfunc1(int); |
||||
-- cleanup |
||||
DROP PROCEDURE ptest1; |
||||
DROP PROCEDURE ptest2; |
||||
DROP TABLE cp_test; |
||||
DROP USER regress_user1; |
@ -0,0 +1,79 @@ |
||||
CALL nonexistent(); -- error |
||||
CALL random(); -- error |
||||
|
||||
CREATE FUNCTION testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$; |
||||
|
||||
CREATE TABLE cp_test (a int, b text); |
||||
|
||||
CREATE PROCEDURE ptest1(x text) |
||||
LANGUAGE SQL |
||||
AS $$ |
||||
INSERT INTO cp_test VALUES (1, x); |
||||
$$; |
||||
|
||||
SELECT ptest1('x'); -- error |
||||
CALL ptest1('a'); -- ok |
||||
|
||||
\df ptest1 |
||||
|
||||
SELECT * FROM cp_test ORDER BY a; |
||||
|
||||
|
||||
CREATE PROCEDURE ptest2() |
||||
LANGUAGE SQL |
||||
AS $$ |
||||
SELECT 5; |
||||
$$; |
||||
|
||||
CALL ptest2(); |
||||
|
||||
|
||||
-- various error cases |
||||
|
||||
CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; |
||||
CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; |
||||
CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; |
||||
|
||||
ALTER PROCEDURE ptest1(text) STRICT; |
||||
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function |
||||
ALTER PROCEDURE testfunc1(int) VOLATILE; -- error: not a procedure |
||||
ALTER PROCEDURE nonexistent() VOLATILE; |
||||
|
||||
DROP FUNCTION ptest1(text); -- error: not a function |
||||
DROP PROCEDURE testfunc1(int); -- error: not a procedure |
||||
DROP PROCEDURE nonexistent(); |
||||
|
||||
|
||||
-- privileges |
||||
|
||||
CREATE USER regress_user1; |
||||
GRANT INSERT ON cp_test TO regress_user1; |
||||
REVOKE EXECUTE ON PROCEDURE ptest1(text) FROM PUBLIC; |
||||
SET ROLE regress_user1; |
||||
CALL ptest1('a'); -- error |
||||
RESET ROLE; |
||||
GRANT EXECUTE ON PROCEDURE ptest1(text) TO regress_user1; |
||||
SET ROLE regress_user1; |
||||
CALL ptest1('a'); -- ok |
||||
RESET ROLE; |
||||
|
||||
|
||||
-- ROUTINE syntax |
||||
|
||||
ALTER ROUTINE testfunc1(int) RENAME TO testfunc1a; |
||||
ALTER ROUTINE testfunc1a RENAME TO testfunc1; |
||||
|
||||
ALTER ROUTINE ptest1(text) RENAME TO ptest1a; |
||||
ALTER ROUTINE ptest1a RENAME TO ptest1; |
||||
|
||||
DROP ROUTINE testfunc1(int); |
||||
|
||||
|
||||
-- cleanup |
||||
|
||||
DROP PROCEDURE ptest1; |
||||
DROP PROCEDURE ptest2; |
||||
|
||||
DROP TABLE cp_test; |
||||
|
||||
DROP USER regress_user1; |
Loading…
Reference in new issue