66 char aggKind = AGGKIND_NORMAL;
75 bool finalfuncExtraArgs =
false;
76 bool mfinalfuncExtraArgs =
false;
77 char finalfuncModify = 0;
78 char mfinalfuncModify = 0;
84 int32 mtransSpace = 0;
86 char *minitval = NULL;
87 char *parallel = NULL;
89 int numDirectArgs = 0;
94 List *parameterDefaults;
99 char mtransTypeType = 0;
100 char proparallel = PROPARALLEL_UNSAFE;
117 if (numDirectArgs >= 0)
118 aggKind = AGGKIND_ORDERED_SET;
125 foreach(pl, parameters)
133 if (strcmp(defel->
defname,
"sfunc") == 0)
135 else if (strcmp(defel->
defname,
"sfunc1") == 0)
137 else if (strcmp(defel->
defname,
"finalfunc") == 0)
139 else if (strcmp(defel->
defname,
"combinefunc") == 0)
141 else if (strcmp(defel->
defname,
"serialfunc") == 0)
143 else if (strcmp(defel->
defname,
"deserialfunc") == 0)
145 else if (strcmp(defel->
defname,
"msfunc") == 0)
147 else if (strcmp(defel->
defname,
"minvfunc") == 0)
149 else if (strcmp(defel->
defname,
"mfinalfunc") == 0)
151 else if (strcmp(defel->
defname,
"finalfunc_extra") == 0)
153 else if (strcmp(defel->
defname,
"mfinalfunc_extra") == 0)
155 else if (strcmp(defel->
defname,
"finalfunc_modify") == 0)
157 else if (strcmp(defel->
defname,
"mfinalfunc_modify") == 0)
159 else if (strcmp(defel->
defname,
"sortop") == 0)
161 else if (strcmp(defel->
defname,
"basetype") == 0)
163 else if (strcmp(defel->
defname,
"hypothetical") == 0)
167 if (aggKind == AGGKIND_NORMAL)
169 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
170 errmsg(
"only ordered-set aggregates can be hypothetical")));
171 aggKind = AGGKIND_HYPOTHETICAL;
174 else if (strcmp(defel->
defname,
"stype") == 0)
176 else if (strcmp(defel->
defname,
"stype1") == 0)
178 else if (strcmp(defel->
defname,
"sspace") == 0)
180 else if (strcmp(defel->
defname,
"mstype") == 0)
182 else if (strcmp(defel->
defname,
"msspace") == 0)
184 else if (strcmp(defel->
defname,
"initcond") == 0)
186 else if (strcmp(defel->
defname,
"initcond1") == 0)
188 else if (strcmp(defel->
defname,
"minitcond") == 0)
190 else if (strcmp(defel->
defname,
"parallel") == 0)
194 (
errcode(ERRCODE_SYNTAX_ERROR),
195 errmsg(
"aggregate attribute \"%s\" not recognized",
202 if (transType == NULL)
204 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
205 errmsg(
"aggregate stype must be specified")));
206 if (transfuncName ==
NIL)
208 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
209 errmsg(
"aggregate sfunc must be specified")));
216 if (mtransType != NULL)
218 if (mtransfuncName ==
NIL)
220 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
221 errmsg(
"aggregate msfunc must be specified when mstype is specified")));
222 if (minvtransfuncName ==
NIL)
224 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
225 errmsg(
"aggregate minvfunc must be specified when mstype is specified")));
229 if (mtransfuncName !=
NIL)
231 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
232 errmsg(
"aggregate msfunc must not be specified without mstype")));
233 if (minvtransfuncName !=
NIL)
235 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
236 errmsg(
"aggregate minvfunc must not be specified without mstype")));
237 if (mfinalfuncName !=
NIL)
239 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
240 errmsg(
"aggregate mfinalfunc must not be specified without mstype")));
241 if (mtransSpace != 0)
243 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
244 errmsg(
"aggregate msspace must not be specified without mstype")));
245 if (minitval != NULL)
247 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
248 errmsg(
"aggregate minitcond must not be specified without mstype")));
255 if (finalfuncModify == 0)
256 finalfuncModify = (aggKind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
257 if (mfinalfuncModify == 0)
258 mfinalfuncModify = (aggKind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
274 if (baseType == NULL)
276 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
277 errmsg(
"aggregate input type must be specified")));
290 allParameterTypes = NULL;
291 parameterModes = NULL;
292 parameterNames = NULL;
293 parameterDefaults =
NIL;
302 Oid requiredResultType;
304 if (baseType != NULL)
306 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
307 errmsg(
"basetype is redundant with aggregate input type specification")));
322 &requiredResultType);
342 if (transTypeType == TYPTYPE_PSEUDO &&
343 !IsPolymorphicType(transTypeId))
345 if (transTypeId == INTERNALOID &&
superuser())
349 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
350 errmsg(
"aggregate transition data type cannot be %s",
354 if (serialfuncName && deserialfuncName)
359 if (transTypeId != INTERNALOID)
361 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
362 errmsg(
"serialization functions may be specified only when the aggregate transition data type is %s",
365 else if (serialfuncName || deserialfuncName)
371 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
372 errmsg(
"must specify both or neither of serialization and deserialization functions")));
383 if (mtransTypeType == TYPTYPE_PSEUDO &&
384 !IsPolymorphicType(mtransTypeId))
386 if (mtransTypeId == INTERNALOID &&
superuser())
390 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
391 errmsg(
"aggregate transition data type cannot be %s",
405 if (initval && transTypeType != TYPTYPE_PSEUDO)
417 if (minitval && mtransTypeType != TYPTYPE_PSEUDO)
428 if (strcmp(parallel,
"safe") == 0)
429 proparallel = PROPARALLEL_SAFE;
430 else if (strcmp(parallel,
"restricted") == 0)
431 proparallel = PROPARALLEL_RESTRICTED;
432 else if (strcmp(parallel,
"unsafe") == 0)
433 proparallel = PROPARALLEL_UNSAFE;
436 (
errcode(ERRCODE_SYNTAX_ERROR),
437 errmsg(
"parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
485 if (strcmp(
val,
"read_only") == 0)
486 return AGGMODIFY_READ_ONLY;
487 if (strcmp(
val,
"shareable") == 0)
488 return AGGMODIFY_SHAREABLE;
489 if (strcmp(
val,
"read_write") == 0)
490 return AGGMODIFY_READ_WRITE;
492 (
errcode(ERRCODE_SYNTAX_ERROR),
493 errmsg(
"parameter \"%s\" must be READ_ONLY, SHAREABLE, or READ_WRITE",
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
static char extractModify(DefElem *defel)
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters, bool replace)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
char * get_namespace_name(Oid nspid)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
char get_typtype(Oid typid)
Oid QualifiedNameGetCreationNamespace(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)
#define PointerGetDatum(X)