aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/functioncmds.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2018-03-02 08:57:38 -0500
committerPeter Eisentraut <peter_e@gmx.net>2018-03-02 13:48:33 -0500
commitfd1a421fe66173fb9b85d3fe150afde8e812cbe4 (patch)
tree24c80c87337ec2d1bb46ee8463207d0cfff5ffc3 /src/backend/commands/functioncmds.c
parent1733460f0205fc6d6bbe4c14911049a918c6e073 (diff)
downloadpostgresql-fd1a421fe66173fb9b85d3fe150afde8e812cbe4.tar.gz
postgresql-fd1a421fe66173fb9b85d3fe150afde8e812cbe4.zip
Add prokind column, replacing proisagg and proiswindow
The new column distinguishes normal functions, procedures, aggregates, and window functions. This replaces the existing columns proisagg and proiswindow, and replaces the convention that procedures are indicated by prorettype == 0. Also change prorettype to be VOIDOID for procedures. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Michael Paquier <michael@paquier.xyz>
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r--src/backend/commands/functioncmds.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index abdfa249c01..b1f87d056e5 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1003,9 +1003,12 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
if (stmt->is_procedure)
{
+ /*
+ * Sometime in the future, procedures might be allowed to return
+ * results; for now, they all return VOID.
+ */
Assert(!stmt->returnType);
-
- prorettype = InvalidOid;
+ prorettype = VOIDOID;
returnsSet = false;
}
else if (stmt->returnType)
@@ -1097,8 +1100,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
languageValidator,
prosrc_str, /* converted to text later */
probin_str, /* converted to text later */
- false, /* not an aggregate */
- isWindowFunc,
+ stmt->is_procedure ? PROKIND_PROCEDURE : (isWindowFunc ? PROKIND_WINDOW : PROKIND_FUNCTION),
security,
isLeakProof,
isStrict,
@@ -1126,7 +1128,7 @@ RemoveFunctionById(Oid funcOid)
{
Relation relation;
HeapTuple tup;
- bool isagg;
+ char prokind;
/*
* Delete the pg_proc tuple.
@@ -1137,7 +1139,7 @@ RemoveFunctionById(Oid funcOid)
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for function %u", funcOid);
- isagg = ((Form_pg_proc) GETSTRUCT(tup))->proisagg;
+ prokind = ((Form_pg_proc) GETSTRUCT(tup))->prokind;
CatalogTupleDelete(relation, &tup->t_self);
@@ -1148,7 +1150,7 @@ RemoveFunctionById(Oid funcOid)
/*
* If there's a pg_aggregate tuple, delete that too.
*/
- if (isagg)
+ if (prokind == PROKIND_AGGREGATE)
{
relation = heap_open(AggregateRelationId, RowExclusiveLock);
@@ -1203,13 +1205,13 @@ AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
aclcheck_error(ACLCHECK_NOT_OWNER, stmt->objtype,
NameListToString(stmt->func->objname));
- if (procForm->proisagg)
+ if (procForm->prokind == PROKIND_AGGREGATE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function",
NameListToString(stmt->func->objname))));
- is_procedure = (procForm->prorettype == InvalidOid);
+ is_procedure = (procForm->prokind == PROKIND_PROCEDURE);
/* Examine requested actions. */
foreach(l, stmt->actions)
@@ -1525,14 +1527,10 @@ CreateCast(CreateCastStmt *stmt)
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("cast function must not be volatile")));
#endif
- if (procstruct->proisagg)
+ if (procstruct->prokind != PROKIND_FUNCTION)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("cast function must not be an aggregate function")));
- if (procstruct->proiswindow)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("cast function must not be a window function")));
+ errmsg("cast function must be a normal function")));
if (procstruct->proretset)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
@@ -1777,14 +1775,10 @@ check_transform_function(Form_pg_proc procstruct)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("transform function must not be volatile")));
- if (procstruct->proisagg)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("transform function must not be an aggregate function")));
- if (procstruct->proiswindow)
+ if (procstruct->prokind != PROKIND_FUNCTION)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("transform function must not be a window function")));
+ errmsg("transform function must be a normal function")));
if (procstruct->proretset)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),