postgres.git / summary / log / commit / refs
commit d2ac26eb9b1e8ad19fd526efb0ffff4fae5ed56f
Author: Peter Eisentraut <peter@eisentraut.org>
Date: Mon Aug 03 08:14:30 2026 +0000
Fix missing space before WHERE in GRAPH_TABLE deparse
get_graph_pattern_def() emitted the pattern-level WHERE keyword as
"WHERE " with no leading space, so reverse-parsing produced output
like "(o IS orders)WHERE (...)". The element-level WHERE deparse in
get_path_pattern_expr_def() already prepends a separating space; the
pattern-level branch was inconsistent with it. Emit " WHERE " to
match.
The output still re-parses to the same tree, so this is cosmetic.
For test coverage, add a whole-pattern WHERE clause to the existing
customers_us view, which is already reverse-parsed with
pg_get_viewdef().
Author: Dhruv Chauhan <chauhandhruv351@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CANWwWcpHb0h7tg6otRnL-FV83jwQpAiyw1bhvv8T78kpwZ-0ow%40mail.gmail.com
src/backend/utils/adt/ruleutils.c | 2 +-
src/test/regress/expected/graph_table.out | 21 +++++++++++----------
src/test/regress/sql/graph_table.sql | 5 +++--
3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 24bf1fbbc21..b5a9c8be56e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -8135,7 +8135,7 @@ get_graph_pattern_def(GraphPattern *graph_pattern, deparse_context *context)
if (graph_pattern->whereClause)
{
- appendStringInfoString(buf, "WHERE ");
+ appendStringInfoString(buf, " WHERE ");
get_rule_expr(graph_pattern->whereClause, context, false);
}
}
diff --git a/src/test/regress/expected/graph_table.out b/src/test/regress/expected/graph_table.out
index 46566b2e32f..b7a6182457d 100644
--- a/src/test/regress/expected/graph_table.out
+++ b/src/test/regress/expected/graph_table.out
@@ -965,13 +965,14 @@ SELECT * FROM GRAPH_TABLE (g4 MATCH (s WHERE s.id = 3)-[e]-(d) COLUMNS (s.val, e
-- GRAPH_TABLE in views
-- The query in the view definition is intentionally complex to test one view with many
--- features like label disjunction, lateral references, WHERE clauses in graph
--- patterns.
+-- features like label disjunction, lateral references, WHERE clauses on graph
+-- pattern elements as well as on the whole graph pattern.
CREATE VIEW customers_us AS
SELECT g.* FROM x1,
GRAPH_TABLE (myshop MATCH (c IS customers WHERE c.address = 'US' AND c.customer_id = x1.a)
-[IS customer_orders | customer_wishlists ]->
(l IS orders | wishlists)-[ IS list_items]->(p IS products)
+ WHERE p.price > 0
COLUMNS (c.name AS customer_name, p.name AS product_name, p.price, x1.a AS a)) g
ORDER BY customer_name, product_name;
-- Dropping properties or labels used by a view is not allowed
@@ -993,14 +994,14 @@ DETAIL: view customers_us depends on property price of property graph myshop
HINT: Use DROP ... CASCADE to drop the dependent objects too.
-- ruleutils reverse parsing
SELECT pg_get_viewdef('customers_us'::regclass);
- pg_get_viewdef
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- SELECT g.customer_name, +
- g.product_name, +
- g.price, +
- g.a +
- FROM x1, +
- GRAPH_TABLE (myshop MATCH (c IS customers WHERE (((c.address)::text = 'US'::text) AND (c.customer_id = x1.a)))-[IS customer_orders|customer_wishlists]->(l IS orders|wishlists)-[IS list_items]->(p IS products) COLUMNS (c.name AS customer_name, p.name AS product_name, p.price AS price, x1.a AS a)) g+
+ pg_get_viewdef
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ SELECT g.customer_name, +
+ g.product_name, +
+ g.price, +
+ g.a +
+ FROM x1, +
+ GRAPH_TABLE (myshop MATCH (c IS customers WHERE (((c.address)::text = 'US'::text) AND (c.customer_id = x1.a)))-[IS customer_orders|customer_wishlists]->(l IS orders|wishlists)-[IS list_items]->(p IS products) WHERE (p.price > (0)::numeric) COLUMNS (c.name AS customer_name, p.name AS product_name, p.price AS price, x1.a AS a)) g+
ORDER BY g.customer_name, g.product_name;
(1 row)
diff --git a/src/test/regress/sql/graph_table.sql b/src/test/regress/sql/graph_table.sql
index 3fb0e50ddb2..85298f93964 100644
--- a/src/test/regress/sql/graph_table.sql
+++ b/src/test/regress/sql/graph_table.sql
@@ -539,13 +539,14 @@ SELECT * FROM GRAPH_TABLE (g4 MATCH (s WHERE s.id = 3)-[e]-(d) COLUMNS (s.val, e
-- GRAPH_TABLE in views
-- The query in the view definition is intentionally complex to test one view with many
--- features like label disjunction, lateral references, WHERE clauses in graph
--- patterns.
+-- features like label disjunction, lateral references, WHERE clauses on graph
+-- pattern elements as well as on the whole graph pattern.
CREATE VIEW customers_us AS
SELECT g.* FROM x1,
GRAPH_TABLE (myshop MATCH (c IS customers WHERE c.address = 'US' AND c.customer_id = x1.a)
-[IS customer_orders | customer_wishlists ]->
(l IS orders | wishlists)-[ IS list_items]->(p IS products)
+ WHERE p.price > 0
COLUMNS (c.name AS customer_name, p.name AS product_name, p.price, x1.a AS a)) g
ORDER BY customer_name, product_name;
-- Dropping properties or labels used by a view is not allowed
[parent: 3fb599b26411]