Skip to content

Commit 47f164f

Browse files
authored
Fix issue 1953 - PG Boolean used as AGTYPE object (#1971)
Fixed issue 1953 - Server crashes when executing - SELECT * FROM cypher('ag_graph_3'...) This was due to the executor phase trying to use a PG Boolean as an AGTYPE object for the indirection argument. The fix was to use coerce_to_common_type on the input argument in transform_A_Indirection. Added regression tests.
1 parent d9cbd6b commit 47f164f

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

regress/expected/expr.out

+48
Original file line numberDiff line numberDiff line change
@@ -8426,8 +8426,56 @@ ERROR: argument 1: key must not be null
84268426
SELECT agtype_build_map('name', 'John', 'null'::agtype, 1);
84278427
ERROR: argument 3: key must not be null
84288428
--
8429+
-- Issue 1953 - crash when trying to use a boolean as an object
8430+
--
8431+
SELECT * FROM create_graph('issue_1953');
8432+
NOTICE: graph "issue_1953" has been created
8433+
create_graph
8434+
--------------
8435+
8436+
(1 row)
8437+
8438+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[{}][{}][{}][{}][{}] $$) AS (result agtype);
8439+
ERROR: A_indirection could not convert type boolean to agtype
8440+
LINE 1: ...ypher('issue_1953', $$ RETURN delete_global_graphs('issue_19...
8441+
^
8442+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[{}] $$) AS (result agtype);
8443+
ERROR: A_indirection could not convert type boolean to agtype
8444+
LINE 1: ...ypher('issue_1953', $$ RETURN delete_global_graphs('issue_19...
8445+
^
8446+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[0] $$) AS (result agtype);
8447+
ERROR: A_indirection could not convert type boolean to agtype
8448+
LINE 1: ...ypher('issue_1953', $$ RETURN delete_global_graphs('issue_19...
8449+
^
8450+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[0..1] $$) AS (result agtype);
8451+
ERROR: A_indirection could not convert type boolean to agtype
8452+
LINE 1: ...ypher('issue_1953', $$ RETURN delete_global_graphs('issue_19...
8453+
^
8454+
SELECT * FROM cypher('issue_1953', $$ RETURN is_valid_label_name('issue_1953')[{}] $$) AS (result agtype);
8455+
ERROR: A_indirection could not convert type boolean to agtype
8456+
LINE 1: ...cypher('issue_1953', $$ RETURN is_valid_label_name('issue_19...
8457+
^
8458+
SELECT * FROM cypher('issue_1953', $$ RETURN is_valid_label_name('issue_1953')[0] $$) AS (result agtype);
8459+
ERROR: A_indirection could not convert type boolean to agtype
8460+
LINE 1: ...cypher('issue_1953', $$ RETURN is_valid_label_name('issue_19...
8461+
^
8462+
SELECT * FROM cypher('issue_1953', $$ RETURN is_valid_label_name('issue_1953')[0..1] $$) AS (result agtype);
8463+
ERROR: A_indirection could not convert type boolean to agtype
8464+
LINE 1: ...cypher('issue_1953', $$ RETURN is_valid_label_name('issue_19...
8465+
^
8466+
--
84298467
-- Cleanup
84308468
--
8469+
SELECT * FROM drop_graph('issue_1953', true);
8470+
NOTICE: drop cascades to 2 other objects
8471+
DETAIL: drop cascades to table issue_1953._ag_label_vertex
8472+
drop cascades to table issue_1953._ag_label_edge
8473+
NOTICE: graph "issue_1953" has been dropped
8474+
drop_graph
8475+
------------
8476+
8477+
(1 row)
8478+
84318479
SELECT * FROM drop_graph('expanded_map', true);
84328480
NOTICE: drop cascades to 2 other objects
84338481
DETAIL: drop cascades to table expanded_map._ag_label_vertex

regress/sql/expr.sql

+14
Original file line numberDiff line numberDiff line change
@@ -3431,9 +3431,23 @@ SELECT agtype_build_map('null'::agtype, 1);
34313431
SELECT agtype_build_map(null, 1);
34323432
SELECT agtype_build_map('name', 'John', 'null'::agtype, 1);
34333433

3434+
--
3435+
-- Issue 1953 - crash when trying to use a boolean as an object
3436+
--
3437+
SELECT * FROM create_graph('issue_1953');
3438+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[{}][{}][{}][{}][{}] $$) AS (result agtype);
3439+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[{}] $$) AS (result agtype);
3440+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[0] $$) AS (result agtype);
3441+
SELECT * FROM cypher('issue_1953', $$ RETURN delete_global_graphs('issue_1953')[0..1] $$) AS (result agtype);
3442+
3443+
SELECT * FROM cypher('issue_1953', $$ RETURN is_valid_label_name('issue_1953')[{}] $$) AS (result agtype);
3444+
SELECT * FROM cypher('issue_1953', $$ RETURN is_valid_label_name('issue_1953')[0] $$) AS (result agtype);
3445+
SELECT * FROM cypher('issue_1953', $$ RETURN is_valid_label_name('issue_1953')[0..1] $$) AS (result agtype);
3446+
34343447
--
34353448
-- Cleanup
34363449
--
3450+
SELECT * FROM drop_graph('issue_1953', true);
34373451
SELECT * FROM drop_graph('expanded_map', true);
34383452
SELECT * FROM drop_graph('issue_1124', true);
34393453
SELECT * FROM drop_graph('issue_1303', true);

src/backend/parser/cypher_expr.c

+4
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ static Node *transform_column_ref_for_indirection(cypher_parsestate *cpstate,
13311331
static Node *transform_A_Indirection(cypher_parsestate *cpstate,
13321332
A_Indirection *a_ind)
13331333
{
1334+
ParseState *pstate = &cpstate->pstate;
13341335
int location;
13351336
ListCell *lc = NULL;
13361337
Node *ind_arg_expr = NULL;
@@ -1369,6 +1370,9 @@ static Node *transform_A_Indirection(cypher_parsestate *cpstate,
13691370
ind_arg_expr = transform_cypher_expr_recurse(cpstate, a_ind->arg);
13701371
}
13711372

1373+
ind_arg_expr = coerce_to_common_type(pstate, ind_arg_expr, AGTYPEOID,
1374+
"A_indirection");
1375+
13721376
/* get the location of the expression */
13731377
location = exprLocation(ind_arg_expr);
13741378

0 commit comments

Comments
 (0)