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

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>
This commit is contained in:
Peter Eisentraut
2018-03-02 08:57:38 -05:00
parent 1733460f02
commit fd1a421fe6
40 changed files with 3246 additions and 3174 deletions

View File

@@ -74,8 +74,7 @@ ProcedureCreate(const char *procedureName,
Oid languageValidator,
const char *prosrc,
const char *probin,
bool isAgg,
bool isWindowFunc,
char prokind,
bool security_definer,
bool isLeakProof,
bool isStrict,
@@ -335,8 +334,7 @@ ProcedureCreate(const char *procedureName,
values[Anum_pg_proc_prorows - 1] = Float4GetDatum(prorows);
values[Anum_pg_proc_provariadic - 1] = ObjectIdGetDatum(variadicType);
values[Anum_pg_proc_protransform - 1] = ObjectIdGetDatum(InvalidOid);
values[Anum_pg_proc_proisagg - 1] = BoolGetDatum(isAgg);
values[Anum_pg_proc_proiswindow - 1] = BoolGetDatum(isWindowFunc);
values[Anum_pg_proc_prokind - 1] = CharGetDatum(prokind);
values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(security_definer);
values[Anum_pg_proc_proleakproof - 1] = BoolGetDatum(isLeakProof);
values[Anum_pg_proc_proisstrict - 1] = BoolGetDatum(isStrict);
@@ -403,6 +401,21 @@ ProcedureCreate(const char *procedureName,
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
procedureName);
/* Not okay to change routine kind */
if (oldproc->prokind != prokind)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot change routine kind"),
(oldproc->prokind == PROKIND_AGGREGATE ?
errdetail("\"%s\" is an aggregate function.", procedureName) :
oldproc->prokind == PROKIND_FUNCTION ?
errdetail("\"%s\" is a function.", procedureName) :
oldproc->prokind == PROKIND_PROCEDURE ?
errdetail("\"%s\" is a procedure.", procedureName) :
oldproc->prokind == PROKIND_WINDOW ?
errdetail("\"%s\" is a window function.", procedureName) :
0)));
/*
* Not okay to change the return type of the existing proc, since
* existing rules, views, etc may depend on the return type.
@@ -535,34 +548,6 @@ ProcedureCreate(const char *procedureName,
}
}
/* Can't change aggregate or window-function status, either */
if (oldproc->proisagg != isAgg)
{
if (oldproc->proisagg)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function \"%s\" is an aggregate function",
procedureName)));
else
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function \"%s\" is not an aggregate function",
procedureName)));
}
if (oldproc->proiswindow != isWindowFunc)
{
if (oldproc->proiswindow)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function \"%s\" is a window function",
procedureName)));
else
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function \"%s\" is not a window function",
procedureName)));
}
/*
* Do not change existing ownership or permissions, either. Note
* dependency-update code below has to agree with this decision.
@@ -857,8 +842,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
/* Disallow pseudotype result */
/* except for RECORD, VOID, or polymorphic */
if (proc->prorettype &&
get_typtype(proc->prorettype) == TYPTYPE_PSEUDO &&
if (get_typtype(proc->prorettype) == TYPTYPE_PSEUDO &&
proc->prorettype != RECORDOID &&
proc->prorettype != VOIDOID &&
!IsPolymorphicType(proc->prorettype))