mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user