mirror of
https://github.com/postgres/postgres.git
synced 2025-11-26 23:43:30 +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:
@@ -199,12 +199,19 @@ PLy_exec_function(FunctionCallInfo fcinfo, PLyProcedure *proc)
|
||||
error_context_stack = &plerrcontext;
|
||||
|
||||
/*
|
||||
* If the function is declared to return void, the Python return value
|
||||
* For a procedure or function declared to return void, the Python return value
|
||||
* must be None. For void-returning functions, we also treat a None
|
||||
* return value as a special "void datum" rather than NULL (as is the
|
||||
* case for non-void-returning functions).
|
||||
*/
|
||||
if (proc->result.typoid == VOIDOID)
|
||||
if (proc->is_procedure)
|
||||
{
|
||||
if (plrv != Py_None)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("PL/Python procedure did not return None")));
|
||||
}
|
||||
else if (proc->result.typoid == VOIDOID)
|
||||
{
|
||||
if (plrv != Py_None)
|
||||
ereport(ERROR,
|
||||
@@ -672,7 +679,8 @@ plpython_return_error_callback(void *arg)
|
||||
{
|
||||
PLyExecutionContext *exec_ctx = PLy_current_execution_context();
|
||||
|
||||
if (exec_ctx->curr_proc)
|
||||
if (exec_ctx->curr_proc &&
|
||||
!exec_ctx->curr_proc->is_procedure)
|
||||
errcontext("while creating return value");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user