diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 6901e08..bbe64a8 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -25,6 +25,7 @@
 #include "postgres.h"
 
 #include "access/sysattr.h"
+#include "catalog/pg_collation.h"
 #include "catalog/pg_type.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
@@ -1996,6 +1997,14 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
 										 (op->op == SETOP_UNION && op->all));
 
 			/* emit results */
+
+			/*
+			 * Ensure that common collation is not invalid when common type
+			 * is TEXT and left and right column type is UNKNOWN.
+			 */
+			if (rescoltype == TEXTOID && !OidIsValid(rescolcoll)
+				&& lcoltype == 705 && rcoltype == 705)
+				rescolcoll = DEFAULT_COLLATION_OID;
 			op->colTypes = lappend_oid(op->colTypes, rescoltype);
 			op->colTypmods = lappend_int(op->colTypmods, rescoltypmod);
 			op->colCollations = lappend_oid(op->colCollations, rescolcoll);
