diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 325a810..6300438 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -17,6 +17,7 @@
 #include "access/heapam.h"
 #include "access/xact.h"
 #include "catalog/namespace.h"
+#include "catalog/pg_type.h"
 #include "commands/defrem.h"
 #include "commands/tablecmds.h"
 #include "commands/view.h"
@@ -24,6 +25,7 @@
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "parser/analyze.h"
+#include "parser/parse_coerce.h"
 #include "parser/parse_relation.h"
 #include "rewrite/rewriteDefine.h"
 #include "rewrite/rewriteManip.h"
@@ -84,6 +86,22 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace,
 	{
 		TargetEntry *tle = (TargetEntry *) lfirst(t);
 
+		Node	   *colnode = (Node *) tle->expr;
+		Oid			coltype = exprType(colnode);
+
+		/*
+		 * If any of targetlist items in view's SELECT list is
+		 * UNKNOWN-type Const, resolve it to type TEXT before creating the view.
+		 * This is to avoid failure in future when the view is accessed.
+		 */
+		if (coltype == UNKNOWNOID && IsA(colnode, Const))
+		{
+				colnode = coerce_type(NULL, colnode, coltype,
+											TEXTOID, -1, COERCION_IMPLICIT,
+												COERCE_IMPLICIT_CAST, -1);
+				tle->expr = (Expr *) colnode;
+		}
+
 		if (!tle->resjunk)
 		{
 			ColumnDef  *def = makeColumnDef(tle->resname,
