1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

SQL procedures

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>
This commit is contained in:
Peter Eisentraut
2017-11-30 08:46:13 -05:00
parent 1761653bbb
commit e4128ee767
92 changed files with 2952 additions and 306 deletions

View File

@@ -657,6 +657,10 @@ standard_ProcessUtility(PlannedStmt *pstmt,
}
break;
case T_CallStmt:
ExecuteCallStmt(pstate, castNode(CallStmt, parsetree));
break;
case T_ClusterStmt:
/* we choose to allow this during "read only" transactions */
PreventCommandDuringRecovery("CLUSTER");
@@ -1957,9 +1961,15 @@ AlterObjectTypeCommandTag(ObjectType objtype)
case OBJECT_POLICY:
tag = "ALTER POLICY";
break;
case OBJECT_PROCEDURE:
tag = "ALTER PROCEDURE";
break;
case OBJECT_ROLE:
tag = "ALTER ROLE";
break;
case OBJECT_ROUTINE:
tag = "ALTER ROUTINE";
break;
case OBJECT_RULE:
tag = "ALTER RULE";
break;
@@ -2261,6 +2271,12 @@ CreateCommandTag(Node *parsetree)
case OBJECT_FUNCTION:
tag = "DROP FUNCTION";
break;
case OBJECT_PROCEDURE:
tag = "DROP PROCEDURE";
break;
case OBJECT_ROUTINE:
tag = "DROP ROUTINE";
break;
case OBJECT_AGGREGATE:
tag = "DROP AGGREGATE";
break;
@@ -2359,7 +2375,20 @@ CreateCommandTag(Node *parsetree)
break;
case T_AlterFunctionStmt:
tag = "ALTER FUNCTION";
switch (((AlterFunctionStmt *) parsetree)->objtype)
{
case OBJECT_FUNCTION:
tag = "ALTER FUNCTION";
break;
case OBJECT_PROCEDURE:
tag = "ALTER PROCEDURE";
break;
case OBJECT_ROUTINE:
tag = "ALTER ROUTINE";
break;
default:
tag = "???";
}
break;
case T_GrantStmt:
@@ -2438,7 +2467,10 @@ CreateCommandTag(Node *parsetree)
break;
case T_CreateFunctionStmt:
tag = "CREATE FUNCTION";
if (((CreateFunctionStmt *) parsetree)->is_procedure)
tag = "CREATE PROCEDURE";
else
tag = "CREATE FUNCTION";
break;
case T_IndexStmt:
@@ -2493,6 +2525,10 @@ CreateCommandTag(Node *parsetree)
tag = "LOAD";
break;
case T_CallStmt:
tag = "CALL";
break;
case T_ClusterStmt:
tag = "CLUSTER";
break;
@@ -3116,6 +3152,10 @@ GetCommandLogLevel(Node *parsetree)
lev = LOGSTMT_ALL;
break;
case T_CallStmt:
lev = LOGSTMT_ALL;
break;
case T_ClusterStmt:
lev = LOGSTMT_DDL;
break;