public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ashutosh Bapat <[email protected]>
To: SATYANARAYANA NARLAPURAM <[email protected]>
Cc: Junwang Zhao <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: [PATCH] Resolve unknown-type literals in GRAPH_TABLE COLUMNS
Date: Wed, 29 Apr 2026 19:39:41 +0530
Message-ID: <CAExHW5vmmAS6Vroh8W9+vmuM2ReocODRCWPqYozGSyhxCxxL+Q@mail.gmail.com> (raw)
In-Reply-To: <CAHg+QDdzUMW4qQmywiPmVo2z3+HccFZL+mujdXbB+ghU21u7dA@mail.gmail.com>
References: <CAHg+QDcyKNWyzDoKMxiZNjv7C-wAxs8y0ZoNkOV137Y+nk3UXg@mail.gmail.com>
	<CAEG8a3KTP1sX+RbPFNST4kHdeRZQR5-dd6kEihV56=K5irrhyQ@mail.gmail.com>
	<CAHg+QDdzUMW4qQmywiPmVo2z3+HccFZL+mujdXbB+ghU21u7dA@mail.gmail.com>

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


Attachments:

  [text/x-patch] v20260429-0001-Resolve-unknown-type-literals-in-GRAPH_TAB.patch (3.0K, 2-v20260429-0001-Resolve-unknown-type-literals-in-GRAPH_TAB.patch)
  download | inline diff:
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+nk3UXg@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



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: <CAExHW5vmmAS6Vroh8W9+vmuM2ReocODRCWPqYozGSyhxCxxL+Q@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