From: Peter Eisentraut Date: Fri, 24 Apr 2026 06:43:26 +0000 (+0200) Subject: Fix collation of expressions in GRAPH_TABLE COLUMNS clause X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=ac3bcc041c5cc2b7ce522d4ce6e6c4653f1263ea;p=thirdparty%2Fpostgresql.git Fix collation of expressions in GRAPH_TABLE COLUMNS clause GRAPH_TABLE clause is converted into a rangetable entry, which is ignored by assign_query_collations(). Hence we assign collations while transforming its parts. But expressions in COLUMNS clause missed that treatment, so fix that. While at it, also add comments about collation assignment to the parts of GRAPH_TABLE clause, and also fix a small grammar issue. Reported-by: Satyanarayana Narlapuram Author: Satyanarayana Narlapuram Author: Ashutosh Bapat Discussion: https://www.postgresql.org/message-id/CAHg+QDc4aaiufYSgrwMMPMMRTPtQ66SghcrPFbWJFZMqNaG+BA@mail.gmail.com --- diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 967eea44f1c..4270c2382c4 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -1003,6 +1003,12 @@ transformRangeGraphTable(ParseState *pstate, RangeGraphTable *rgt) columns = lappend(columns, te); } + /* + * Assign collations to column expressions now since + * assign_query_collations() does not process rangetable entries. + */ + assign_list_collations(pstate, columns); + table_close(rel, NoLock); pstate->p_graph_table_pstate = NULL; diff --git a/src/backend/parser/parse_graphtable.c b/src/backend/parser/parse_graphtable.c index f889c8df4e3..73fbfb541f7 100644 --- a/src/backend/parser/parse_graphtable.c +++ b/src/backend/parser/parse_graphtable.c @@ -252,6 +252,11 @@ transformGraphElementPattern(ParseState *pstate, GraphElementPattern *gep) gep->labelexpr = transformLabelExpr(gpstate, gep->labelexpr); gep->whereClause = transformExpr(pstate, gep->whereClause, EXPR_KIND_WHERE); + + /* + * Assign collations here for the reason mentioned in the prologue of + * transformGraphPattern(). + */ assign_expr_collations(pstate, gep->whereClause); gpstate->cur_gep = NULL; @@ -366,9 +371,14 @@ transformPathPatternList(ParseState *pstate, List *path_pattern) * Transform a GraphPattern. * * A GraphPattern consists of a list of one or more path patterns and an - * optional where clause. Transform them. We use the previously constructure + * optional where clause. Transform them. We use the previously constructed * list of variables in the GraphTableParseState to resolve property references * in the WHERE clause. + * + * Since most parts of the GraphPattern do not require collation assignment, we + * assign collations to the required expressions as they are transformed. This + * avoids the need to traverse the whole GraphPattern again and avoids exposing + * it to assign_expr_collations(). */ Node * transformGraphPattern(ParseState *pstate, GraphPattern *graph_pattern) diff --git a/src/test/regress/expected/graph_table.out b/src/test/regress/expected/graph_table.out index b579e3df635..057f283c43d 100644 --- a/src/test/regress/expected/graph_table.out +++ b/src/test/regress/expected/graph_table.out @@ -652,13 +652,13 @@ SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-(a) COLUMNS (a.vname AS self)); v33 (1 row) --- test collation specified in the expression +-- test explicit and implicit collation assignment INSERT INTO e3_3 VALUES (2003, 2003, 'E331', 10011); -SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(a)-[b]->(a) COLUMNS (a.vname AS self, b.ename AS loop_name)) ORDER BY loop_name COLLATE "C" ASC; +SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(a)-[b]->(a) COLUMNS (upper(a.vname) AS self, b.ename AS loop_name)) ORDER BY loop_name COLLATE "C" ASC; self | loop_name ------+----------- - v33 | E331 - v33 | e331 + V33 | E331 + V33 | e331 (2 rows) SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b IS el2 WHERE b.ename > 'E331' COLLATE "C"]->(a)-[b]->(a) COLUMNS (a.vname AS self, b.ename AS loop_name)); diff --git a/src/test/regress/sql/graph_table.sql b/src/test/regress/sql/graph_table.sql index 4ff98817420..278064818ff 100644 --- a/src/test/regress/sql/graph_table.sql +++ b/src/test/regress/sql/graph_table.sql @@ -394,9 +394,9 @@ SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(c)-[b]->(d) COLUMNS (a.vname AS an SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[c]-(a) COLUMNS (a.vname AS self, c.ename AS loop_name)); SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-(a) COLUMNS (a.vname AS self)); --- test collation specified in the expression +-- test explicit and implicit collation assignment INSERT INTO e3_3 VALUES (2003, 2003, 'E331', 10011); -SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(a)-[b]->(a) COLUMNS (a.vname AS self, b.ename AS loop_name)) ORDER BY loop_name COLLATE "C" ASC; +SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(a)-[b]->(a) COLUMNS (upper(a.vname) AS self, b.ename AS loop_name)) ORDER BY loop_name COLLATE "C" ASC; SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b IS el2 WHERE b.ename > 'E331' COLLATE "C"]->(a)-[b]->(a) COLUMNS (a.vname AS self, b.ename AS loop_name)); SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(a)-[b]->(a) WHERE b.ename > 'E331' COLLATE "C" COLUMNS (a.vname AS self, b.ename AS loop_name)); SELECT * FROM GRAPH_TABLE (g1 MATCH (a)-[b]->(a)-[b]->(a) COLUMNS (a.vname AS self, b.ename AS loop_name)) WHERE loop_name > 'E331' COLLATE "C";