mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Coerce GRAPH_TABLE pattern WHERE clauses to boolean
transformGraphElementPattern() and transformGraphPattern() ran their WHERE clauses through transformExpr() without ever applying coerce_to_boolean(), so a WHERE clause of any type was accepted and its bare datum was used as the qual, which resulted in wrong results without a diagnostic. Route both sites through transformWhereClause(), like every other WHERE clause, and add regression tests for the element-level and pattern-level cases. Author: Ewan Young <kdbase.hack@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAON2xHNZUS8ZwzVEJFeRirsC_-7EJvdbwABSzdGaJ_DF9DvHoQ%40mail.gmail.com
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "catalog/pg_propgraph_property.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "parser/parse_clause.h"
|
||||
#include "parser/parse_collate.h"
|
||||
#include "parser/parse_expr.h"
|
||||
#include "parser/parse_graphtable.h"
|
||||
@@ -251,7 +252,8 @@ transformGraphElementPattern(ParseState *pstate, GraphElementPattern *gep)
|
||||
|
||||
gep->labelexpr = transformLabelExpr(gpstate, gep->labelexpr);
|
||||
|
||||
gep->whereClause = transformExpr(pstate, gep->whereClause, EXPR_KIND_WHERE);
|
||||
gep->whereClause = transformWhereClause(pstate, gep->whereClause,
|
||||
EXPR_KIND_WHERE, "WHERE");
|
||||
|
||||
/*
|
||||
* Assign collations here for the reason mentioned in the prologue of
|
||||
@@ -387,7 +389,8 @@ transformGraphPattern(ParseState *pstate, GraphPattern *graph_pattern)
|
||||
transformPathPatternList(pstate, graph_pattern->path_pattern_list));
|
||||
|
||||
graph_pattern->path_pattern_list = path_pattern_list;
|
||||
graph_pattern->whereClause = transformExpr(pstate, graph_pattern->whereClause, EXPR_KIND_WHERE);
|
||||
graph_pattern->whereClause = transformWhereClause(pstate, graph_pattern->whereClause,
|
||||
EXPR_KIND_WHERE, "WHERE");
|
||||
assign_expr_collations(pstate, graph_pattern->whereClause);
|
||||
|
||||
return (Node *) graph_pattern;
|
||||
|
||||
@@ -101,6 +101,10 @@ LINE 1: SELECT * FROM GRAPH_TABLE (myshop MATCH COLUMNS (1 AS col));
|
||||
^
|
||||
SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers)->{1,2}(o IS orders) COLUMNS (c.name AS customer_name)); -- error
|
||||
ERROR: element pattern quantifier is not supported
|
||||
SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers WHERE c.name) COLUMNS (c.name AS customer_name)); -- error, WHERE must yield boolean
|
||||
ERROR: argument of WHERE must be type boolean, not type character varying
|
||||
SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers) WHERE c.customer_id COLUMNS (c.name AS customer_name)); -- error, WHERE must yield boolean
|
||||
ERROR: argument of WHERE must be type boolean, not type integer
|
||||
SELECT * FROM GRAPH_TABLE (myshop MATCH ((c IS customers)->(o IS orders)) COLUMNS (c.name));
|
||||
ERROR: unsupported element pattern kind: "nested path pattern"
|
||||
LINE 1: SELECT * FROM GRAPH_TABLE (myshop MATCH ((c IS customers)->(...
|
||||
|
||||
@@ -92,6 +92,8 @@ SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers WHERE c.addr
|
||||
SELECT * FROM GRAPH_TABLE (myshop MATCH (c IS customers), (o IS orders) COLUMNS (c.name AS customer_name)); -- error
|
||||
SELECT * FROM GRAPH_TABLE (myshop MATCH COLUMNS (1 AS col)); -- error, empty match clause
|
||||
SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers)->{1,2}(o IS orders) COLUMNS (c.name AS customer_name)); -- error
|
||||
SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers WHERE c.name) COLUMNS (c.name AS customer_name)); -- error, WHERE must yield boolean
|
||||
SELECT customer_name FROM GRAPH_TABLE (myshop MATCH (c IS customers) WHERE c.customer_id COLUMNS (c.name AS customer_name)); -- error, WHERE must yield boolean
|
||||
SELECT * FROM GRAPH_TABLE (myshop MATCH ((c IS customers)->(o IS orders)) COLUMNS (c.name));
|
||||
|
||||
-- a property graph can be referenced only from within GRAPH_TABLE clause.
|
||||
|
||||
Reference in New Issue
Block a user