63 char aggKind = AGGKIND_NORMAL;
72 bool finalfuncExtraArgs =
false;
73 bool mfinalfuncExtraArgs =
false;
74 char finalfuncModify = 0;
75 char mfinalfuncModify = 0;
81 int32 mtransSpace = 0;
83 char *minitval = NULL;
84 char *parallel = NULL;
86 int numDirectArgs = 0;
91 List *parameterDefaults;
96 char mtransTypeType = 0;
97 char proparallel = PROPARALLEL_UNSAFE;
114 if (numDirectArgs >= 0)
115 aggKind = AGGKIND_ORDERED_SET;
122 foreach(pl, parameters)
130 if (strcmp(defel->
defname,
"sfunc") == 0)
132 else if (strcmp(defel->
defname,
"sfunc1") == 0)
134 else if (strcmp(defel->
defname,
"finalfunc") == 0)
136 else if (strcmp(defel->
defname,
"combinefunc") == 0)
138 else if (strcmp(defel->
defname,
"serialfunc") == 0)
140 else if (strcmp(defel->
defname,
"deserialfunc") == 0)
142 else if (strcmp(defel->
defname,
"msfunc") == 0)
144 else if (strcmp(defel->
defname,
"minvfunc") == 0)
146 else if (strcmp(defel->
defname,
"mfinalfunc") == 0)
148 else if (strcmp(defel->
defname,
"finalfunc_extra") == 0)
150 else if (strcmp(defel->
defname,
"mfinalfunc_extra") == 0)
152 else if (strcmp(defel->
defname,
"finalfunc_modify") == 0)
154 else if (strcmp(defel->
defname,
"mfinalfunc_modify") == 0)
156 else if (strcmp(defel->
defname,
"sortop") == 0)
158 else if (strcmp(defel->
defname,
"basetype") == 0)
160 else if (strcmp(defel->
defname,
"hypothetical") == 0)
164 if (aggKind == AGGKIND_NORMAL)
166 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
167 errmsg(
"only ordered-set aggregates can be hypothetical")));
168 aggKind = AGGKIND_HYPOTHETICAL;
171 else if (strcmp(defel->
defname,
"stype") == 0)
173 else if (strcmp(defel->
defname,
"stype1") == 0)
175 else if (strcmp(defel->
defname,
"sspace") == 0)
177 else if (strcmp(defel->
defname,
"mstype") == 0)
179 else if (strcmp(defel->
defname,
"msspace") == 0)
181 else if (strcmp(defel->
defname,
"initcond") == 0)
183 else if (strcmp(defel->
defname,
"initcond1") == 0)
185 else if (strcmp(defel->
defname,
"minitcond") == 0)
187 else if (strcmp(defel->
defname,
"parallel") == 0)
191 (
errcode(ERRCODE_SYNTAX_ERROR),
192 errmsg(
"aggregate attribute \"%s\" not recognized",
199 if (transType == NULL)
201 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
202 errmsg(
"aggregate stype must be specified")));
203 if (transfuncName ==
NIL)
205 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
206 errmsg(
"aggregate sfunc must be specified")));
213 if (mtransType != NULL)
215 if (mtransfuncName ==
NIL)
217 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
218 errmsg(
"aggregate msfunc must be specified when mstype is specified")));
219 if (minvtransfuncName ==
NIL)
221 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
222 errmsg(
"aggregate minvfunc must be specified when mstype is specified")));
226 if (mtransfuncName !=
NIL)
228 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
229 errmsg(
"aggregate msfunc must not be specified without mstype")));
230 if (minvtransfuncName !=
NIL)
232 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
233 errmsg(
"aggregate minvfunc must not be specified without mstype")));
234 if (mfinalfuncName !=
NIL)
236 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
237 errmsg(
"aggregate mfinalfunc must not be specified without mstype")));
238 if (mtransSpace != 0)
240 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
241 errmsg(
"aggregate msspace must not be specified without mstype")));
242 if (minitval != NULL)
244 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
245 errmsg(
"aggregate minitcond must not be specified without mstype")));
252 if (finalfuncModify == 0)
253 finalfuncModify = (aggKind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
254 if (mfinalfuncModify == 0)
255 mfinalfuncModify = (aggKind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
271 if (baseType == NULL)
273 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
274 errmsg(
"aggregate input type must be specified")));
287 allParameterTypes = NULL;
288 parameterModes = NULL;
289 parameterNames = NULL;
290 parameterDefaults =
NIL;
299 Oid requiredResultType;
301 if (baseType != NULL)
303 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
304 errmsg(
"basetype is redundant with aggregate input type specification")));
319 &requiredResultType);
339 if (transTypeType == TYPTYPE_PSEUDO &&
340 !IsPolymorphicType(transTypeId))
342 if (transTypeId == INTERNALOID &&
superuser())
346 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
347 errmsg(
"aggregate transition data type cannot be %s",
351 if (serialfuncName && deserialfuncName)
356 if (transTypeId != INTERNALOID)
358 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
359 errmsg(
"serialization functions may be specified only when the aggregate transition data type is %s",
362 else if (serialfuncName || deserialfuncName)
368 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
369 errmsg(
"must specify both or neither of serialization and deserialization functions")));
380 if (mtransTypeType == TYPTYPE_PSEUDO &&
381 !IsPolymorphicType(mtransTypeId))
383 if (mtransTypeId == INTERNALOID &&
superuser())
387 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
388 errmsg(
"aggregate transition data type cannot be %s",
402 if (initval && transTypeType != TYPTYPE_PSEUDO)
414 if (minitval && mtransTypeType != TYPTYPE_PSEUDO)
425 if (strcmp(parallel,
"safe") == 0)
426 proparallel = PROPARALLEL_SAFE;
427 else if (strcmp(parallel,
"restricted") == 0)
428 proparallel = PROPARALLEL_RESTRICTED;
429 else if (strcmp(parallel,
"unsafe") == 0)
430 proparallel = PROPARALLEL_UNSAFE;
433 (
errcode(ERRCODE_SYNTAX_ERROR),
434 errmsg(
"parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
482 if (strcmp(
val,
"read_only") == 0)
483 return AGGMODIFY_READ_ONLY;
484 if (strcmp(
val,
"shareable") == 0)
485 return AGGMODIFY_SHAREABLE;
486 if (strcmp(
val,
"read_write") == 0)
487 return AGGMODIFY_READ_WRITE;
489 (
errcode(ERRCODE_SYNTAX_ERROR),
490 errmsg(
"parameter \"%s\" must be READ_ONLY, SHAREABLE, or READ_WRITE",
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
static char extractModify(DefElem *defel)
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters, bool replace)
#define Assert(condition)
int32 defGetInt32(DefElem *def)
bool defGetBoolean(DefElem *def)
List * defGetQualifiedName(DefElem *def)
char * defGetString(DefElem *def)
TypeName * defGetTypeName(DefElem *def)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
void interpret_function_parameter_list(ParseState *pstate, List *parameters, Oid languageOid, ObjectType objtype, oidvector **parameterTypes, List **parameterTypes_list, ArrayType **allParameterTypes, ArrayType **parameterModes, ArrayType **parameterNames, List **inParameterNames_list, List **parameterDefaults, Oid *variadicArgType, Oid *requiredResultType)
char * get_namespace_name(Oid nspid)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
char get_typtype(Oid typid)
Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p)
oidvector * buildoidvector(const Oid *oids, int n)
char * TypeNameToString(const TypeName *typeName)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
ObjectAddress AggregateCreate(const char *aggName, Oid aggNamespace, bool replace, char aggKind, int numArgs, int numDirectArgs, oidvector *parameterTypes, Datum allParameterTypes, Datum parameterModes, Datum parameterNames, List *parameterDefaults, Oid variadicArgType, List *aggtransfnName, List *aggfinalfnName, List *aggcombinefnName, List *aggserialfnName, List *aggdeserialfnName, List *aggmtransfnName, List *aggminvtransfnName, List *aggmfinalfnName, bool finalfnExtraArgs, bool mfinalfnExtraArgs, char finalfnModify, char mfinalfnModify, List *aggsortopName, Oid aggTransType, int32 aggTransSpace, Oid aggmTransType, int32 aggmTransSpace, const char *agginitval, const char *aggminitval, char proparallel)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
int pg_strcasecmp(const char *s1, const char *s2)
static Datum PointerGetDatum(const void *X)