Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wwKuC-001uiC-2x for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Aug 2026 14:35:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wwKu9-00GBt7-1C for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Aug 2026 14:35:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wwKu8-00GBsz-33 for pgsql-hackers@lists.postgresql.org; Tue, 18 Aug 2026 14:35:06 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wwKu7-00000001ECi-3QUt for pgsql-hackers@lists.postgresql.org; Tue, 18 Aug 2026 14:35:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67IEZ1cS1379593; Tue, 18 Aug 2026 10:35:01 -0400 From: Tom Lane To: David Rowley cc: Andrei Lepikhov , PostgreSQL Hackers , Corey Huinker Subject: Re: Allow a prosupport function to be attached to an aggregate In-reply-to: References: <8f58c96d-d3c7-4c0f-9898-116f00eeaff6@gmail.com> Comments: In-reply-to David Rowley message dated "Tue, 18 Aug 2026 16:56:59 +1200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1379580.1787063694.0@sss.pgh.pa.us> Date: Tue, 18 Aug 2026 10:35:01 -0400 Message-ID: <1379592.1787063701@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1379580.1787063694.1@sss.pgh.pa.us> David Rowley writes: > I failed to realise that there was no way to set that for user-defined > aggregates. Not good. While I do agree that lack of extensibility is > not aligned with the spirit of the project, my current thoughts are > that now is a bit late to add this to v19. > Is delaying this until v20 fine for you? > Or does anyone else feel this is a must-fix for v19? That seems quite sad. The entire point of the support-function mechanism is to allow extensibility, so if an extension cannot use a support hook we have totally failed at implementing that hook. (As you yourself remarked in a different context, it's unlikely we would have implemented SupportRequestSimplifyAggref if the only possible use-case was COUNT(any).) So I think it's a must-fix. To put my money where my mouth is, here's a draft patch. (I could not resist the temptation to improve compute_common_attribute's existing error message, which pretty well sucks: it's useless in a context that's not showing you an accurate error pointer.) regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="v1-allow-alter-aggregate-support.patch"; charset="us-ascii" Content-ID: <1379580.1787063694.2@sss.pgh.pa.us> Content-Description: v1-allow-alter-aggregate-support.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/fu= nctioncmds.c index ba24a708982..ee778502b8a 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -516,7 +516,7 @@ interpret_function_parameter_list(ParseState *pstate, */ static bool compute_common_attribute(ParseState *pstate, - bool is_procedure, + char prokind, DefElem *defel, DefElem **volatility_item, DefElem **strict_item, @@ -528,8 +528,13 @@ compute_common_attribute(ParseState *pstate, DefElem **support_item, DefElem **parallel_item) { + bool is_aggregate =3D (prokind =3D=3D PROKIND_AGGREGATE); + bool is_procedure =3D (prokind =3D=3D PROKIND_PROCEDURE); + if (strcmp(defel->defname, "volatility") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (is_procedure) goto procedure_error; if (*volatility_item) @@ -539,6 +544,8 @@ compute_common_attribute(ParseState *pstate, } else if (strcmp(defel->defname, "strict") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (is_procedure) goto procedure_error; if (*strict_item) @@ -548,6 +555,8 @@ compute_common_attribute(ParseState *pstate, } else if (strcmp(defel->defname, "security") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (*security_item) errorConflictingDefElem(defel, pstate); = @@ -555,6 +564,8 @@ compute_common_attribute(ParseState *pstate, } else if (strcmp(defel->defname, "leakproof") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (is_procedure) goto procedure_error; if (*leakproof_item) @@ -564,10 +575,14 @@ compute_common_attribute(ParseState *pstate, } else if (strcmp(defel->defname, "set") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; *set_items =3D lappend(*set_items, defel->arg); } else if (strcmp(defel->defname, "cost") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (is_procedure) goto procedure_error; if (*cost_item) @@ -577,6 +592,8 @@ compute_common_attribute(ParseState *pstate, } else if (strcmp(defel->defname, "rows") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (is_procedure) goto procedure_error; if (*rows_item) @@ -595,6 +612,8 @@ compute_common_attribute(ParseState *pstate, } else if (strcmp(defel->defname, "parallel") =3D=3D 0) { + if (is_aggregate) + goto aggregate_error; if (is_procedure) goto procedure_error; if (*parallel_item) @@ -608,10 +627,19 @@ compute_common_attribute(ParseState *pstate, /* Recognized an option */ return true; = +aggregate_error: + ereport(ERROR, + (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), + errmsg("attribute \"%s\" is not allowed for aggregates", + defel->defname), + parser_errposition(pstate, defel->location))); + return false; + procedure_error: ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), - errmsg("invalid attribute in procedure definition"), + errmsg("attribute \"%s\" is not allowed for procedures", + defel->defname), parser_errposition(pstate, defel->location))); return false; } @@ -730,7 +758,7 @@ interpret_func_support(DefElem *defel) */ static void compute_function_attributes(ParseState *pstate, - bool is_procedure, + char prokind, List *options, List **as, char **language, @@ -787,15 +815,16 @@ compute_function_attributes(ParseState *pstate, { if (windowfunc_item) errorConflictingDefElem(defel, pstate); - if (is_procedure) + if (prokind =3D=3D PROKIND_PROCEDURE) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), - errmsg("invalid attribute in procedure definition"), + errmsg("attribute \"%s\" is not allowed for procedures", + defel->defname), parser_errposition(pstate, defel->location))); windowfunc_item =3D defel; } else if (compute_common_attribute(pstate, - is_procedure, + prokind, defel, &volatility_item, &strict_item, @@ -1052,6 +1081,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStm= t *stmt) List *trfoids_list =3D NIL; ArrayType *trftypes; Oid requiredResultType; + char prokind; bool isWindowFunc, isStrict, security, @@ -1079,6 +1109,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStm= t *stmt) /* Set default attributes */ as_clause =3D NIL; language =3D NULL; + prokind =3D (stmt->is_procedure ? PROKIND_PROCEDURE : PROKIND_FUNCTION); isWindowFunc =3D false; isStrict =3D false; security =3D false; @@ -1092,7 +1123,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStm= t *stmt) = /* Extract non-default attributes from stmt->options list */ compute_function_attributes(pstate, - stmt->is_procedure, + prokind, stmt->options, &as_clause, &language, &transformDefElem, &isWindowFunc, &volatility, @@ -1100,6 +1131,16 @@ CreateFunction(ParseState *pstate, CreateFunctionSt= mt *stmt) &proconfig, &procost, &prorows, &prosupport, ¶llel); = + /* + * If we found a WINDOW attribute, change prokind accordingly. Note tha= t + * as things stand, we must allow all the same attributes for window + * functions as plain functions, since we don't know the difference whil= e + * scanning the options list. If that ever needs to change, we'd have t= o + * scan the list twice, the first time just to identify WINDOW. + */ + if (isWindowFunc) + prokind =3D PROKIND_WINDOW; + if (!language) { if (stmt->sql_body) @@ -1285,7 +1326,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStm= t *stmt) prosrc_str, /* converted to text later */ probin_str, /* converted to text later */ prosqlbody, - stmt->is_procedure ? PROKIND_PROCEDURE : (isWindowFunc ? PROKIND= _WINDOW : PROKIND_FUNCTION), + prokind, security, isLeakProof, isStrict, @@ -1366,7 +1407,6 @@ AlterFunction(ParseState *pstate, AlterFunctionStmt = *stmt) HeapTuple tup; Oid funcOid; Form_pg_proc procForm; - bool is_procedure; Relation rel; ListCell *l; DefElem *volatility_item =3D NULL; @@ -1397,21 +1437,13 @@ AlterFunction(ParseState *pstate, AlterFunctionStm= t *stmt) aclcheck_error(ACLCHECK_NOT_OWNER, stmt->objtype, NameListToString(stmt->func->objname)); = - if (procForm->prokind =3D=3D PROKIND_AGGREGATE) - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("\"%s\" is an aggregate function", - NameListToString(stmt->func->objname)))); - - is_procedure =3D (procForm->prokind =3D=3D PROKIND_PROCEDURE); - /* Examine requested actions. */ foreach(l, stmt->actions) { DefElem *defel =3D (DefElem *) lfirst(l); = if (compute_common_attribute(pstate, - is_procedure, + procForm->prokind, defel, &volatility_item, &strict_item, diff --git a/src/test/regress/expected/create_procedure.out b/src/test/reg= ress/expected/create_procedure.out index f89042cf798..48170c008db 100644 --- a/src/test/regress/expected/create_procedure.out +++ b/src/test/regress/expected/create_procedure.out @@ -392,11 +392,11 @@ LINE 1: CALL sum(1); ^ HINT: To call a function, use SELECT. CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT INTO cp_test V= ALUES (1, 'a') $$; -ERROR: invalid attribute in procedure definition +ERROR: attribute "window" is not allowed for procedures LINE 1: CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT I... ^ CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT INTO cp_test V= ALUES (1, 'a') $$; -ERROR: invalid attribute in procedure definition +ERROR: attribute "strict" is not allowed for procedures LINE 1: CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT I... ^ CREATE PROCEDURE ptestx(a VARIADIC int[], b OUT int) LANGUAGE SQL @@ -410,7 +410,7 @@ ERROR: procedure OUT parameters cannot appear after o= ne with a default value LINE 1: CREATE PROCEDURE ptestx(a int DEFAULT 42, b OUT int) LANGUAG... ^ ALTER PROCEDURE ptest1(text) STRICT; -ERROR: invalid attribute in procedure definition +ERROR: attribute "strict" is not allowed for procedures LINE 1: ALTER PROCEDURE ptest1(text) STRICT; ^ ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function ------- =_aaaaaaaaaa0--