diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 0cf7b9e..f1eb362 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -490,13 +490,12 @@ CheckAttributeType(const char *attname,
 	if (atttypid == UNKNOWNOID)
 	{
 		/*
-		 * Warn user, but don't fail, if column to be created has UNKNOWN type
+		 * Refuse to create relation if column to be created has UNKNOWN type
 		 * (usually as a result of a 'retrieve into' - jolly)
 		 */
-		ereport(WARNING,
+		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
-				 errmsg("column \"%s\" has type \"unknown\"", attname),
-				 errdetail("Proceeding with relation creation anyway.")));
+				 errmsg("column \"%s\" has type \"unknown\"", attname)));
 	}
 	else if (att_typtype == TYPTYPE_PSEUDO)
 	{
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,
diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out
index 66ed2c8..8171a6b 100644
--- a/src/test/regress/expected/create_view.out
+++ b/src/test/regress/expected/create_view.out
@@ -1530,6 +1530,16 @@ select pg_get_viewdef('tt19v', true);
      'foo'::text = ANY ((( SELECT ARRAY['abc'::text, 'def'::text, 'foo'::text] AS "array"))::text[]) AS c2;
 (1 row)
 
+-- check coercion of UNKNOWN type to text for literal constants
+create view v as select 'abc' a;
+create view v11 as select 'def' a;
+select a from v UNION select a from v11;
+  a  
+-----
+ abc
+ def
+(2 rows)
+
 -- clean up all the random objects we made above
 set client_min_messages = warning;
 DROP SCHEMA temp_view_test CASCADE;
diff --git a/src/test/regress/sql/create_view.sql b/src/test/regress/sql/create_view.sql
index 8bed5a5..660ff2f 100644
--- a/src/test/regress/sql/create_view.sql
+++ b/src/test/regress/sql/create_view.sql
@@ -507,6 +507,11 @@ select 'foo'::text = any(array['abc','def','foo']::text[]) c1,
        'foo'::text = any((select array['abc','def','foo']::text[])::text[]) c2;
 select pg_get_viewdef('tt19v', true);
 
+-- check coercion of UNKNOWN type to text for literal constants
+create view v as select 'abc' a;
+create view v11 as select 'def' a;
+select a from v UNION select a from v11;
+
 -- clean up all the random objects we made above
 set client_min_messages = warning;
 DROP SCHEMA temp_view_test CASCADE;
