diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index d25b8ad505d..00f92d1dc7d 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -2724,7 +2724,7 @@ hash_numeric(PG_FUNCTION_ARGS)
 
 	/* If it's NaN or infinity, don't try to hash the rest of the fields */
 	if (NUMERIC_IS_SPECIAL(key))
-		PG_RETURN_UINT32(0);
+		PG_RETURN_INT32(0);
 
 	weight = NUMERIC_WEIGHT(key);
 	start_offset = 0;
@@ -2756,7 +2756,7 @@ hash_numeric(PG_FUNCTION_ARGS)
 	 * regardless of any other fields.
 	 */
 	if (NUMERIC_NDIGITS(key) == start_offset)
-		PG_RETURN_UINT32(-1);
+		PG_RETURN_INT32(-1);
 
 	for (i = NUMERIC_NDIGITS(key) - 1; i >= 0; i--)
 	{
@@ -2782,7 +2782,7 @@ hash_numeric(PG_FUNCTION_ARGS)
 	/* Mix in the weight, via XOR */
 	result = digit_hash ^ weight;
 
-	PG_RETURN_DATUM(result);
+	PG_RETURN_INT32(DatumGetInt32(result));
 }
 
 /*
