Skip to content

Commit ba0da16

Browse files
committed
Require callers of coerce_to_domain() to supply base type/typmod.
In view of the issue fixed in commit 0da39aa, it no longer seems like a great idea for coerce_to_domain() to offer to perform a lookup that its caller probably should have done already. The caller should be providing a value of the domain's base type, so it's hard to envision a valid case where it hasn't looked up that type. After 0da39aa there is only one caller using the option for internal lookup, and that one can trivially be rearranged to not do that. So this seems more like a bug-encouraging misfeature than a useful shortcut; let's get rid of it (in HEAD only, there's no need to break any external callers in back branches). Discussion: https://postgr.es/m/1865579.1738113656@sss.pgh.pa.us
1 parent 0da39aa commit ba0da16

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/backend/parser/parse_coerce.c

+12-14
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ coerce_type(ParseState *pstate, Node *node,
414414
&funcId);
415415
if (pathtype != COERCION_PATH_NONE)
416416
{
417+
Oid baseTypeId;
418+
int32 baseTypeMod;
419+
420+
baseTypeMod = targetTypeMod;
421+
baseTypeId = getBaseTypeAndTypmod(targetTypeId, &baseTypeMod);
422+
417423
if (pathtype != COERCION_PATH_RELABELTYPE)
418424
{
419425
/*
@@ -423,12 +429,6 @@ coerce_type(ParseState *pstate, Node *node,
423429
* and we need to extract the correct typmod to use from the
424430
* domain's typtypmod.
425431
*/
426-
Oid baseTypeId;
427-
int32 baseTypeMod;
428-
429-
baseTypeMod = targetTypeMod;
430-
baseTypeId = getBaseTypeAndTypmod(targetTypeId, &baseTypeMod);
431-
432432
result = build_coercion_expression(node, pathtype, funcId,
433433
baseTypeId, baseTypeMod,
434434
ccontext, cformat, location);
@@ -454,7 +454,8 @@ coerce_type(ParseState *pstate, Node *node,
454454
* that must be accounted for. If the destination is a domain
455455
* then we won't need a RelabelType node.
456456
*/
457-
result = coerce_to_domain(node, InvalidOid, -1, targetTypeId,
457+
result = coerce_to_domain(node, baseTypeId, baseTypeMod,
458+
targetTypeId,
458459
ccontext, cformat, location,
459460
false);
460461
if (result == node)
@@ -660,10 +661,8 @@ can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids,
660661
* Create an expression tree to represent coercion to a domain type.
661662
*
662663
* 'arg': input expression
663-
* 'baseTypeId': base type of domain, if known (pass InvalidOid if caller
664-
* has not bothered to look this up)
665-
* 'baseTypeMod': base type typmod of domain, if known (pass -1 if caller
666-
* has not bothered to look this up)
664+
* 'baseTypeId': base type of domain
665+
* 'baseTypeMod': base type typmod of domain
667666
* 'typeId': target type to coerce to
668667
* 'ccontext': context indicator to control coercions
669668
* 'cformat': coercion display format
@@ -679,9 +678,8 @@ coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId,
679678
{
680679
CoerceToDomain *result;
681680

682-
/* Get the base type if it hasn't been supplied */
683-
if (baseTypeId == InvalidOid)
684-
baseTypeId = getBaseTypeAndTypmod(typeId, &baseTypeMod);
681+
/* We now require the caller to supply correct baseTypeId/baseTypeMod */
682+
Assert(OidIsValid(baseTypeId));
685683

686684
/* If it isn't a domain, return the node as it was passed in */
687685
if (baseTypeId == typeId)

0 commit comments

Comments
 (0)