mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Add select_common_typmod()
This accompanies select_common_type() and select_common_collation(). Typmods were previously combined using hand-coded logic in several places. The logic in select_common_typmod() isn't very exciting, but it makes the code more compact and readable in a few locations, and in the future we can perhaps do more complicated things if desired. As a small enhancement, the type unification of the direct and aggregate arguments of hypothetical-set aggregates now unifies the typmod as well using this new function, instead of just dropping it. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://www.postgresql.org/message-id/flat/97df3af9-8b5e-fb7f-a029-3eb7e80d7af9@2ndquadrant.com
This commit is contained in:
@ -1750,6 +1750,7 @@ unify_hypothetical_args(ParseState *pstate,
|
||||
ListCell *harg = list_nth_cell(fargs, hargpos);
|
||||
ListCell *aarg = list_nth_cell(fargs, aargpos);
|
||||
Oid commontype;
|
||||
int32 commontypmod;
|
||||
|
||||
/* A mismatch means AggregateCreate didn't check properly ... */
|
||||
if (declared_arg_types[hargpos] != declared_arg_types[aargpos])
|
||||
@ -1768,6 +1769,9 @@ unify_hypothetical_args(ParseState *pstate,
|
||||
list_make2(lfirst(aarg), lfirst(harg)),
|
||||
"WITHIN GROUP",
|
||||
NULL);
|
||||
commontypmod = select_common_typmod(pstate,
|
||||
list_make2(lfirst(aarg), lfirst(harg)),
|
||||
commontype);
|
||||
|
||||
/*
|
||||
* Perform the coercions. We don't need to worry about NamedArgExprs
|
||||
@ -1776,7 +1780,7 @@ unify_hypothetical_args(ParseState *pstate,
|
||||
lfirst(harg) = coerce_type(pstate,
|
||||
(Node *) lfirst(harg),
|
||||
actual_arg_types[hargpos],
|
||||
commontype, -1,
|
||||
commontype, commontypmod,
|
||||
COERCION_IMPLICIT,
|
||||
COERCE_IMPLICIT_CAST,
|
||||
-1);
|
||||
@ -1784,7 +1788,7 @@ unify_hypothetical_args(ParseState *pstate,
|
||||
lfirst(aarg) = coerce_type(pstate,
|
||||
(Node *) lfirst(aarg),
|
||||
actual_arg_types[aargpos],
|
||||
commontype, -1,
|
||||
commontype, commontypmod,
|
||||
COERCION_IMPLICIT,
|
||||
COERCE_IMPLICIT_CAST,
|
||||
-1);
|
||||
|
Reference in New Issue
Block a user