diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index ebda55d..7f314f5 100644
*** a/src/backend/parser/parse_expr.c
--- b/src/backend/parser/parse_expr.c
*************** transformAExprIn(ParseState *pstate, A_E
*** 1163,1168 ****
--- 1163,1181 ----
  		scalar_type = select_common_type(pstate, allexprs, NULL, NULL);
  
  		/*
+ 		 * If the common type is varchar, use text, to skip the inevitable
+ 		 * coercion later (since varchar depends on text's operators).  This
+ 		 * is pretty ugly, but it's hard to see how to do it in a more
+ 		 * principled way; there are seemingly-equivalent cases where we do
+ 		 * NOT want to substitute the comparison operator's actual input type.
+ 		 * For example, replacing regclass by oid would break several useful
+ 		 * cases in the regression tests.  Varchar is common enough that it
+ 		 * seems worth a kluge here.
+ 		 */
+ 		if (scalar_type == VARCHAROID)
+ 			scalar_type = TEXTOID;
+ 
+ 		/*
  		 * Do we have an array type to use?  Aside from the case where there
  		 * isn't one, we don't risk using ScalarArrayOpExpr when the common
  		 * type is RECORD, because the RowExpr comparison logic below can cope
