diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c
index 872574f..86ef127 100644
--- a/src/backend/utils/adt/format_type.c
+++ b/src/backend/utils/adt/format_type.c
@@ -63,6 +63,7 @@ format_type(PG_FUNCTION_ARGS)
 	Oid			type_oid;
 	int32		typemod;
 	char	   *result;
+	bits16		flags = FORMAT_TYPE_ALLOW_INVALID;
 
 	/* Since this function is not strict, we must test for null args */
 	if (PG_ARGISNULL(0))
@@ -71,9 +72,10 @@ format_type(PG_FUNCTION_ARGS)
 	type_oid = PG_GETARG_OID(0);
 	typemod = PG_ARGISNULL(1) ? -1 : PG_GETARG_INT32(1);
 
-	result = format_type_extended(type_oid, typemod,
-								  FORMAT_TYPE_TYPEMOD_GIVEN |
-								  FORMAT_TYPE_ALLOW_INVALID);
+	if (typemod != -1)
+		flags |= FORMAT_TYPE_TYPEMOD_GIVEN;
+
+	result = format_type_extended(type_oid, typemod, flags);
 
 	PG_RETURN_TEXT_P(cstring_to_text(result));
 }
