67 char aggKind = AGGKIND_NORMAL;
76 bool finalfuncExtraArgs =
false;
77 bool mfinalfuncExtraArgs =
false;
78 char finalfuncModify = 0;
79 char mfinalfuncModify = 0;
85 int32 mtransSpace = 0;
87 char *minitval = NULL;
88 char *parallel = NULL;
90 int numDirectArgs = 0;
95 List *parameterDefaults;
100 char mtransTypeType = 0;
101 char proparallel = PROPARALLEL_UNSAFE;
118 if (numDirectArgs >= 0)
119 aggKind = AGGKIND_ORDERED_SET;
126 foreach(pl, parameters)
134 if (strcmp(defel->
defname,
"sfunc") == 0)
136 else if (strcmp(defel->
defname,
"sfunc1") == 0)
138 else if (strcmp(defel->
defname,
"finalfunc") == 0)
140 else if (strcmp(defel->
defname,
"combinefunc") == 0)
142 else if (strcmp(defel->
defname,
"serialfunc") == 0)
144 else if (strcmp(defel->
defname,
"deserialfunc") == 0)
146 else if (strcmp(defel->
defname,
"msfunc") == 0)
148 else if (strcmp(defel->
defname,
"minvfunc") == 0)
150 else if (strcmp(defel->
defname,
"mfinalfunc") == 0)
152 else if (strcmp(defel->
defname,
"finalfunc_extra") == 0)
154 else if (strcmp(defel->
defname,
"mfinalfunc_extra") == 0)
156 else if (strcmp(defel->
defname,
"finalfunc_modify") == 0)
158 else if (strcmp(defel->
defname,
"mfinalfunc_modify") == 0)
160 else if (strcmp(defel->
defname,
"sortop") == 0)
162 else if (strcmp(defel->
defname,
"basetype") == 0)
164 else if (strcmp(defel->
defname,
"hypothetical") == 0)
168 if (aggKind == AGGKIND_NORMAL)
170 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
171 errmsg(
"only ordered-set aggregates can be hypothetical")));
172 aggKind = AGGKIND_HYPOTHETICAL;
175 else if (strcmp(defel->
defname,
"stype") == 0)
177 else if (strcmp(defel->
defname,
"stype1") == 0)
179 else if (strcmp(defel->
defname,
"sspace") == 0)
181 else if (strcmp(defel->
defname,
"mstype") == 0)
183 else if (strcmp(defel->
defname,
"msspace") == 0)
185 else if (strcmp(defel->
defname,
"initcond") == 0)
187 else if (strcmp(defel->
defname,
"initcond1") == 0)
189 else if (strcmp(defel->
defname,
"minitcond") == 0)
191 else if (strcmp(defel->
defname,
"parallel") == 0)
195 (
errcode(ERRCODE_SYNTAX_ERROR),
196 errmsg(
"aggregate attribute \"%s\" not recognized",
203 if (transType == NULL)
205 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
206 errmsg(
"aggregate stype must be specified")));
207 if (transfuncName ==
NIL)
209 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
210 errmsg(
"aggregate sfunc must be specified")));
217 if (mtransType != NULL)
219 if (mtransfuncName ==
NIL)
221 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
222 errmsg(
"aggregate msfunc must be specified when mstype is specified")));
223 if (minvtransfuncName ==
NIL)
225 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
226 errmsg(
"aggregate minvfunc must be specified when mstype is specified")));
230 if (mtransfuncName !=
NIL)
232 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
233 errmsg(
"aggregate msfunc must not be specified without mstype")));
234 if (minvtransfuncName !=
NIL)
236 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
237 errmsg(
"aggregate minvfunc must not be specified without mstype")));
238 if (mfinalfuncName !=
NIL)
240 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
241 errmsg(
"aggregate mfinalfunc must not be specified without mstype")));
242 if (mtransSpace != 0)
244 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
245 errmsg(
"aggregate msspace must not be specified without mstype")));
246 if (minitval != NULL)
248 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
249 errmsg(
"aggregate minitcond must not be specified without mstype")));
256 if (finalfuncModify == 0)
257 finalfuncModify = (aggKind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
258 if (mfinalfuncModify == 0)
259 mfinalfuncModify = (aggKind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
275 if (baseType == NULL)
277 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
278 errmsg(
"aggregate input type must be specified")));
291 allParameterTypes = NULL;
292 parameterModes = NULL;
293 parameterNames = NULL;
294 parameterDefaults =
NIL;
303 Oid requiredResultType;
305 if (baseType != NULL)
307 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
308 errmsg(
"basetype is redundant with aggregate input type specification")));
323 &requiredResultType);
343 if (transTypeType == TYPTYPE_PSEUDO &&
344 !IsPolymorphicType(transTypeId))
346 if (transTypeId == INTERNALOID &&
superuser())
350 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
351 errmsg(
"aggregate transition data type cannot be %s",
355 if (serialfuncName && deserialfuncName)
360 if (transTypeId != INTERNALOID)
362 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
363 errmsg(
"serialization functions may be specified only when the aggregate transition data type is %s",
366 else if (serialfuncName || deserialfuncName)
372 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
373 errmsg(
"must specify both or neither of serialization and deserialization functions")));
384 if (mtransTypeType == TYPTYPE_PSEUDO &&
385 !IsPolymorphicType(mtransTypeId))
387 if (mtransTypeId == INTERNALOID &&
superuser())
391 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
392 errmsg(
"aggregate transition data type cannot be %s",
406 if (initval && transTypeType != TYPTYPE_PSEUDO)
418 if (minitval && mtransTypeType != TYPTYPE_PSEUDO)
429 if (strcmp(parallel,
"safe") == 0)
430 proparallel = PROPARALLEL_SAFE;
431 else if (strcmp(parallel,
"restricted") == 0)
432 proparallel = PROPARALLEL_RESTRICTED;
433 else if (strcmp(parallel,
"unsafe") == 0)
434 proparallel = PROPARALLEL_UNSAFE;
437 (
errcode(ERRCODE_SYNTAX_ERROR),
438 errmsg(
"parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
486 if (strcmp(
val,
"read_only") == 0)
487 return AGGMODIFY_READ_ONLY;
488 if (strcmp(
val,
"shareable") == 0)
489 return AGGMODIFY_SHAREABLE;
490 if (strcmp(
val,
"read_write") == 0)
491 return AGGMODIFY_READ_WRITE;
493 (
errcode(ERRCODE_SYNTAX_ERROR),
494 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)
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(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)