On Mon, Apr 27, 2026 at 11:34 AM SATYANARAYANA NARLAPURAM <[email protected]> wrote: > > Hi, > > On Sun, Apr 26, 2026 at 8:10 AM Junwang Zhao <[email protected]> wrote: >> >> Hi SATYANARAYANA, >> >> On Sun, Apr 26, 2026 at 3:53 AM SATYANARAYANA NARLAPURAM >> <[email protected]> wrote: >> > >> > Hi hackers, >> > >> > transformRangeGraphTable() calls transformExpr() and >> > assign_list_collations() for COLUMNS expressions but missed calling >> > resolveTargetListUnknowns(). As a result, literals such as 'val1' >> > 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 after assign_list_collations(), similar to SELECT target lists >> > in >> > transformSelectStmt(). >> > >> > Attached a patch to fix this, which also includes test cases to reproduce. >> >> I can reproduce this and the patch fixes it. >> >> One question: why is resolveTargetListUnknowns called after >> assign_list_collations? >> >> I'm asking because in transformSelectStmt, resolveTargetListUnknowns >> is invoked before assign_query_collations. It might not matter, but keeping >> the order consistent would be good for readers. > > > Updated the patch. It should be before.
Do we really need a test for ORDER BY on a literal column? I replaced all the test queries with a single one which covers all the scenarios covered by those queries. The patch needed to consider pstate->p_resolve_unknowns. Unknown literals are not resolved as text always. See the test query. -- Best Wishes, Ashutosh Bapat
From c9e6b0df945e90bb0be43c88d1c55e1ee0a9a982 Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat <[email protected]> Date: Wed, 29 Apr 2026 19:07:13 +0530 Subject: [PATCH v20260429 5/5] Resolve unknown-type literals in GRAPH_TABLE COLUMNS The unknown-type literals in the COLUMNS clause of a GRAPH_TABLE are now resolved to the appropriate types, causing various failures. Call resolveTargetListUnknowns() on the columns targetlist to resolve unknonw type literals. Do this before assigning collations so that the resolved types are used for collations assignment. Reported by: Satya Narlapuram <[email protected]> Author: Satya Narlapuram <[email protected]> Author: Ashutosh Bapat <[email protected]> Reviewed by: Junwang Zhao <[email protected]> Discussion: https://www.postgresql.org/message-id/cahg+qdcyknwyzdokmxiznjv7c-waxs8y0zonkov137y+nk3...@mail.gmail.com --- src/backend/parser/parse_clause.c | 4 ++++ src/test/regress/expected/graph_table.out | 11 +++++++++++ src/test/regress/sql/graph_table.sql | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 4270c2382c4..3d0585b8efb 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -1003,6 +1003,10 @@ transformRangeGraphTable(ParseState *pstate, RangeGraphTable *rgt) columns = lappend(columns, te); } + /* resolve any still-unresolved output columns as being type text */ + if (pstate->p_resolve_unknowns) + 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 8038fcd39b7..5ef98e281e6 100644 --- a/src/test/regress/expected/graph_table.out +++ b/src/test/regress/expected/graph_table.out @@ -1047,4 +1047,15 @@ SELECT src.vname, count(*) v11 | 1 (3 rows) +-- Unknown type resolution +SELECT c1, pg_typeof(c1), "null", pg_typeof("null") FROM + (SELECT *FROM GRAPH_TABLE (g1 MATCH (a IS vl1) COLUMNS ('1' AS c1, NULL as "null")) + UNION + SELECT 2, NULL); + c1 | pg_typeof | null | pg_typeof +----+-----------+------+----------- + 1 | integer | | text + 2 | integer | | text +(2 rows) + -- 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 a3681c6c0ef..d3ddcdc8e20 100644 --- a/src/test/regress/sql/graph_table.sql +++ b/src/test/regress/sql/graph_table.sql @@ -599,4 +599,10 @@ SELECT src.vname, count(*) COLUMNS (a.vname AS n)) WHERE n = src.vname); +-- Unknown type resolution +SELECT c1, pg_typeof(c1), "null", pg_typeof("null") FROM + (SELECT *FROM GRAPH_TABLE (g1 MATCH (a IS vl1) COLUMNS ('1' AS c1, NULL as "null")) + UNION + SELECT 2, NULL); + -- leave the objects behind for pg_upgrade/pg_dump tests -- 2.34.1
