mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +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:
@@ -1522,6 +1522,43 @@ coerce_to_common_type(ParseState *pstate, Node *node,
|
||||
return node;
|
||||
}
|
||||
|
||||
/*
|
||||
* select_common_typmod()
|
||||
* Determine the common typmod of a list of input expressions.
|
||||
*
|
||||
* common_type is the selected common type of the expressions, typically
|
||||
* computed using select_common_type().
|
||||
*/
|
||||
int32
|
||||
select_common_typmod(ParseState *pstate, List *exprs, Oid common_type)
|
||||
{
|
||||
ListCell *lc;
|
||||
bool first = true;
|
||||
int32 result = -1;
|
||||
|
||||
foreach(lc, exprs)
|
||||
{
|
||||
Node *expr = (Node *) lfirst(lc);
|
||||
|
||||
/* Types must match */
|
||||
if (exprType(expr) != common_type)
|
||||
return -1;
|
||||
else if (first)
|
||||
{
|
||||
result = exprTypmod(expr);
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* As soon as we see a non-matching typmod, fall back to -1 */
|
||||
if (result != exprTypmod(expr))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* check_generic_type_consistency()
|
||||
* Are the actual arguments potentially compatible with a
|
||||
|
Reference in New Issue
Block a user