From: Satya Narlapuram <satyanarlapuram@gmail.com>
Subject: [PATCH] Resolve unknown-type literals in GRAPH_TABLE COLUMNS expressions

transformRangeGraphTable() calls transformExpr() and
assign_list_collations() for COLUMNS expressions but missed calling
resolveTargetListUnknowns(). As a result, literals such as 'col1'
in a COLUMNS clause retained type "unknown", causing failures with
ORDER BY, UNION, and output conversions.

Fix by calling resolveTargetListUnknowns() on the columns target
list right before assign_list_collations(), similar to SELECT target
lists in transformSelectStmt().
---
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index f3736979..f679f510 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -1004,6 +1004,9 @@ transformRangeGraphTable(ParseState *pstate, RangeGraphTable *rgt)
 		columns = lappend(columns, te);
 	}
 
+	/* Resolve unknown-type literals to text */
+	resolveTargetListUnknowns(pstate, columns);
+
 	/*
 	 * Assign collations to column expressions now since
 	 * assign_query_collations() does not process rangetable entries.
diff --git a/src/test/regress/expected/graph_table.out b/src/test/regress/expected/graph_table.out
index d3c20610..212fa29f 100644
--- a/src/test/regress/expected/graph_table.out
+++ b/src/test/regress/expected/graph_table.out
@@ -1110,4 +1110,58 @@ SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1) COLUMNS (upper(a.vname) AS n)) OR
  V13
 (3 rows)
 
+-- String and NULL literals in COLUMNS must resolve to proper types
+-- (not remain as "unknown")
+SELECT pg_typeof(c1), c1
+  FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, 'val1' AS c1)) ORDER BY n;
+ pg_typeof |  c1  
+-----------+------
+ text      | val1
+ text      | val1
+ text      | val1
+(3 rows)
+
+-- ORDER BY on a literal column
+SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, 'val1' AS c1)) ORDER BY c1, n;
+  n  |  c1  
+-----+------
+ v11 | val1
+ v12 | val1
+ v13 | val1
+(3 rows)
+
+-- UNION between GRAPH_TABLE literal column and plain text
+SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, 'val1' AS c1))
+  UNION ALL SELECT 'val2', 'val3';
+  n   |  c1  
+------+------
+ v11  | val1
+ v12  | val1
+ v13  | val1
+ val2 | val3
+(4 rows)
+
+-- NULL literal must not cause failures
+SELECT n, pg_typeof(c1)
+  FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, NULL AS c1)) ORDER BY n;
+  n  | pg_typeof 
+-----+-----------
+ v11 | text
+ v12 | text
+ v13 | text
+(3 rows)
+
+-- integer literal type is preserved
+SELECT pg_typeof(c1)
+  FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (42 AS c1)) LIMIT 1;
+ pg_typeof 
+-----------
+ integer
+(1 row)
+
 -- leave the objects behind for pg_upgrade/pg_dump tests
diff --git a/src/test/regress/sql/graph_table.sql b/src/test/regress/sql/graph_table.sql
index 2521c4ca..3d74ab4c 100644
--- a/src/test/regress/sql/graph_table.sql
+++ b/src/test/regress/sql/graph_table.sql
@@ -634,4 +634,25 @@ SELECT src.vname, count(*)
 SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1) COLUMNS (a.vname || '!' AS n)) ORDER BY n;
 SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1) COLUMNS (upper(a.vname) AS n)) ORDER BY n;
 
+-- String and NULL literals in COLUMNS must resolve to proper types
+-- (not remain as "unknown")
+SELECT pg_typeof(c1), c1
+  FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, 'val1' AS c1)) ORDER BY n;
+-- ORDER BY on a literal column
+SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, 'val1' AS c1)) ORDER BY c1, n;
+-- UNION between GRAPH_TABLE literal column and plain text
+SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, 'val1' AS c1))
+  UNION ALL SELECT 'val2', 'val3';
+-- NULL literal must not cause failures
+SELECT n, pg_typeof(c1)
+  FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (a.vname AS n, NULL AS c1)) ORDER BY n;
+-- integer literal type is preserved
+SELECT pg_typeof(c1)
+  FROM GRAPH_TABLE (g1 MATCH (a IS vl1)
+    COLUMNS (42 AS c1)) LIMIT 1;
+
 -- leave the objects behind for pg_upgrade/pg_dump tests
