public inbox for [email protected]
help / color / mirror / Atom feedFrom: SATYANARAYANA NARLAPURAM <[email protected]>
To: Junwang Zhao <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: Ashutosh Bapat <[email protected]>
Subject: Re: [PATCH] Resolve unknown-type literals in GRAPH_TABLE COLUMNS
Date: Sun, 26 Apr 2026 23:04:32 -0700
Message-ID: <CAHg+QDdzUMW4qQmywiPmVo2z3+HccFZL+mujdXbB+ghU21u7dA@mail.gmail.com> (raw)
In-Reply-To: <CAEG8a3KTP1sX+RbPFNST4kHdeRZQR5-dd6kEihV56=K5irrhyQ@mail.gmail.com>
References: <CAHg+QDcyKNWyzDoKMxiZNjv7C-wAxs8y0ZoNkOV137Y+nk3UXg@mail.gmail.com>
<CAEG8a3KTP1sX+RbPFNST4kHdeRZQR5-dd6kEihV56=K5irrhyQ@mail.gmail.com>
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.
Thanks,
Satya
Attachments:
[application/octet-stream] v2-0001-Resolve-unknown-type-literals-in-GRAPH_TABLE-COLUMNS.patch (4.1K, 3-v2-0001-Resolve-unknown-type-literals-in-GRAPH_TABLE-COLUMNS.patch)
download | inline diff:
From: Satya Narlapuram <[email protected]>
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
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: [PATCH] Resolve unknown-type literals in GRAPH_TABLE COLUMNS
In-Reply-To: <CAHg+QDdzUMW4qQmywiPmVo2z3+HccFZL+mujdXbB+ghU21u7dA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox