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")));
320 &requiredResultType);
340 if (transTypeType == TYPTYPE_PSEUDO &&
341 !IsPolymorphicType(transTypeId))
343 if (transTypeId == INTERNALOID &&
superuser())
347 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
348 errmsg(
"aggregate transition data type cannot be %s",
352 if (serialfuncName && deserialfuncName)
357 if (transTypeId != INTERNALOID)
359 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
360 errmsg(
"serialization functions may be specified only when the aggregate transition data type is %s",
363 else if (serialfuncName || deserialfuncName)
369 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
370 errmsg(
"must specify both or neither of serialization and deserialization functions")));
381 if (mtransTypeType == TYPTYPE_PSEUDO &&
382 !IsPolymorphicType(mtransTypeId))
384 if (mtransTypeId == INTERNALOID &&
superuser())
388 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
389 errmsg(
"aggregate transition data type cannot be %s",
403 if (initval && transTypeType != TYPTYPE_PSEUDO)
415 if (minitval && mtransTypeType != TYPTYPE_PSEUDO)
426 if (strcmp(parallel,
"safe") == 0)
427 proparallel = PROPARALLEL_SAFE;
428 else if (strcmp(parallel,
"restricted") == 0)
429 proparallel = PROPARALLEL_RESTRICTED;
430 else if (strcmp(parallel,
"unsafe") == 0)
431 proparallel = PROPARALLEL_UNSAFE;
434 (
errcode(ERRCODE_SYNTAX_ERROR),
435 errmsg(
"parameter \"parallel\" must be SAFE, RESTRICTED, or UNSAFE")));
Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p)
#define PointerGetDatum(X)
char * TypeNameToString(const TypeName *typeName)
int32 defGetInt32(DefElem *def)
int errcode(int sqlerrcode)
char get_typtype(Oid typid)
int pg_strcasecmp(const char *s1, const char *s2)
#define linitial_node(type, l)
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool defGetBoolean(DefElem *def)
TypeName * defGetTypeName(DefElem *def)
char * defGetString(DefElem *def)
static char extractModify(DefElem *defel)
#define lfirst_node(type, lc)
char * get_namespace_name(Oid nspid)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
#define ereport(elevel,...)
#define Assert(condition)
oidvector * buildoidvector(const Oid *oids, int n)
void interpret_function_parameter_list(ParseState *pstate, List *parameters, Oid languageOid, ObjectType objtype, oidvector **parameterTypes, ArrayType **allParameterTypes, ArrayType **parameterModes, ArrayType **parameterNames, List **parameterDefaults, Oid *variadicArgType, Oid *requiredResultType)
List * defGetQualifiedName(DefElem *def)
static int list_length(const List *l)
int errmsg(const char *fmt,...)
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)
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)