Skip to content

Commit 190354c

Browse files
authored
Fix issue 2243 - Regression in string concatenation (#2244)
Fixed issue 2243 - Regression in string concatenation using the + operator. The issue was in versions 1.5.0 and 1.6.0, at least. It was due to using Int8GetDatum instead of Int64GetDatum for the agtype integer field in the following functions - get_numeric_datum_from_agtype_value get_string_from_agtype_value This impacted more than what the original issue covered, but those additional cases were resolved too. Added regression tests. modified: regress/expected/agtype.out modified: regress/sql/agtype.sql modified: src/backend/utils/adt/agtype_ops.c
1 parent ec45734 commit 190354c

File tree

3 files changed

+150
-2
lines changed

3 files changed

+150
-2
lines changed

regress/expected/agtype.out

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,9 +3776,110 @@ SELECT agtype_build_map('1', '1', 2, 2, 3.14, 3.14, 'e', 2.71);
37763776
{"1": "1", "2": 2, "e": 2.71::numeric, "3.14": 3.14::numeric}
37773777
(1 row)
37783778

3779+
--
3780+
-- Bug found from issue 2043 - Regression in string concatenation using the + operator
3781+
--
3782+
-- This bug impacted specific numeric cases too.
3783+
--
3784+
SELECT * FROM create_graph('issue_2243');
3785+
NOTICE: graph "issue_2243" has been created
3786+
create_graph
3787+
--------------
3788+
3789+
(1 row)
3790+
3791+
SELECT * FROM cypher('issue_2243', $$
3792+
CREATE (n30164502:Node {data_id: 30164502})
3793+
RETURN id(n30164502) + ':test_n' + n30164502.data_id
3794+
$$ ) as (result agtype);
3795+
result
3796+
----------------------------------
3797+
"844424930131969:test_n30164502"
3798+
(1 row)
3799+
3800+
-- concat / add
3801+
SELECT * FROM cypher('issue_2243', $$
3802+
RETURN 9223372036854775807::integer + ":test_n" + 9223372036854775807::integer
3803+
$$ ) as (result agtype);
3804+
result
3805+
-------------------------------------------------
3806+
"9223372036854775807:test_n9223372036854775807"
3807+
(1 row)
3808+
3809+
SELECT * FROM cypher('issue_2243', $$
3810+
RETURN 9223372036854775807::numeric + 9223372036854775807::integer
3811+
$$ ) as (result agtype);
3812+
result
3813+
-------------------------------
3814+
18446744073709551614::numeric
3815+
(1 row)
3816+
3817+
-- sub
3818+
SELECT * FROM cypher('issue_2243', $$
3819+
RETURN 9223372036854775807::numeric - 9223372036854775807::integer
3820+
$$ ) as (result agtype);
3821+
result
3822+
------------
3823+
0::numeric
3824+
(1 row)
3825+
3826+
-- mul
3827+
SELECT * FROM cypher('issue_2243', $$
3828+
RETURN 9223372036854775807::numeric * 9223372036854775807::integer
3829+
$$ ) as (result agtype);
3830+
result
3831+
-------------------------------------------------
3832+
85070591730234615847396907784232501249::numeric
3833+
(1 row)
3834+
3835+
-- div
3836+
SELECT * FROM cypher('issue_2243', $$
3837+
RETURN 9223372036854775807::numeric / 9223372036854775807::integer
3838+
$$ ) as (result agtype);
3839+
result
3840+
---------------------------------
3841+
1.00000000000000000000::numeric
3842+
(1 row)
3843+
3844+
SELECT * FROM cypher('issue_2243', $$
3845+
RETURN 9223372036854775807::integer / 9223372036854775807::numeric
3846+
$$ ) as (result agtype);
3847+
result
3848+
---------------------------------
3849+
1.00000000000000000000::numeric
3850+
(1 row)
3851+
3852+
-- mod
3853+
SELECT * FROM cypher('issue_2243', $$
3854+
RETURN 9223372036854775807::numeric % 9223372036854775807::integer
3855+
$$ ) as (result agtype);
3856+
result
3857+
------------
3858+
0::numeric
3859+
(1 row)
3860+
3861+
SELECT * FROM cypher('issue_2243', $$
3862+
RETURN 9223372036854775807::integer % 9223372036854775807::numeric
3863+
$$ ) as (result agtype);
3864+
result
3865+
------------
3866+
0::numeric
3867+
(1 row)
3868+
37793869
--
37803870
-- Cleanup
37813871
--
3872+
SELECT drop_graph('issue_2243', true);
3873+
NOTICE: drop cascades to 3 other objects
3874+
DETAIL: drop cascades to table issue_2243._ag_label_vertex
3875+
drop cascades to table issue_2243._ag_label_edge
3876+
drop cascades to table issue_2243."Node"
3877+
NOTICE: graph "issue_2243" has been dropped
3878+
drop_graph
3879+
------------
3880+
3881+
(1 row)
3882+
37823883
SELECT drop_graph('agtype_build_map', true);
37833884
NOTICE: drop cascades to 2 other objects
37843885
DETAIL: drop cascades to table agtype_build_map._ag_label_vertex

regress/sql/agtype.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,56 @@ SELECT * FROM cypher('agtype_build_map', $$ RETURN ag_catalog.agtype_build_map('
10751075
$$) AS (results agtype);
10761076
SELECT agtype_build_map('1', '1', 2, 2, 3.14, 3.14, 'e', 2.71);
10771077

1078+
--
1079+
-- Bug found from issue 2043 - Regression in string concatenation using the + operator
1080+
--
1081+
-- This bug impacted specific numeric cases too.
1082+
--
1083+
SELECT * FROM create_graph('issue_2243');
1084+
SELECT * FROM cypher('issue_2243', $$
1085+
CREATE (n30164502:Node {data_id: 30164502})
1086+
RETURN id(n30164502) + ':test_n' + n30164502.data_id
1087+
$$ ) as (result agtype);
1088+
1089+
-- concat / add
1090+
SELECT * FROM cypher('issue_2243', $$
1091+
RETURN 9223372036854775807::integer + ":test_n" + 9223372036854775807::integer
1092+
$$ ) as (result agtype);
1093+
1094+
SELECT * FROM cypher('issue_2243', $$
1095+
RETURN 9223372036854775807::numeric + 9223372036854775807::integer
1096+
$$ ) as (result agtype);
1097+
1098+
-- sub
1099+
SELECT * FROM cypher('issue_2243', $$
1100+
RETURN 9223372036854775807::numeric - 9223372036854775807::integer
1101+
$$ ) as (result agtype);
1102+
1103+
-- mul
1104+
SELECT * FROM cypher('issue_2243', $$
1105+
RETURN 9223372036854775807::numeric * 9223372036854775807::integer
1106+
$$ ) as (result agtype);
1107+
1108+
-- div
1109+
SELECT * FROM cypher('issue_2243', $$
1110+
RETURN 9223372036854775807::numeric / 9223372036854775807::integer
1111+
$$ ) as (result agtype);
1112+
SELECT * FROM cypher('issue_2243', $$
1113+
RETURN 9223372036854775807::integer / 9223372036854775807::numeric
1114+
$$ ) as (result agtype);
1115+
1116+
-- mod
1117+
SELECT * FROM cypher('issue_2243', $$
1118+
RETURN 9223372036854775807::numeric % 9223372036854775807::integer
1119+
$$ ) as (result agtype);
1120+
SELECT * FROM cypher('issue_2243', $$
1121+
RETURN 9223372036854775807::integer % 9223372036854775807::numeric
1122+
$$ ) as (result agtype);
1123+
10781124
--
10791125
-- Cleanup
10801126
--
1127+
SELECT drop_graph('issue_2243', true);
10811128
SELECT drop_graph('agtype_build_map', true);
10821129

10831130
DROP TABLE agtype_table;

src/backend/utils/adt/agtype_ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static char *get_string_from_agtype_value(agtype_value *agtv, int *length)
6868
{
6969
case AGTV_INTEGER:
7070
number = DirectFunctionCall1(int8out,
71-
Int8GetDatum(agtv->val.int_value));
71+
Int64GetDatum(agtv->val.int_value));
7272
string = DatumGetCString(number);
7373
*length = strlen(string);
7474
return string;
@@ -115,7 +115,7 @@ Datum get_numeric_datum_from_agtype_value(agtype_value *agtv)
115115
{
116116
case AGTV_INTEGER:
117117
return DirectFunctionCall1(int8_numeric,
118-
Int8GetDatum(agtv->val.int_value));
118+
Int64GetDatum(agtv->val.int_value));
119119
case AGTV_FLOAT:
120120
return DirectFunctionCall1(float8_numeric,
121121
Float8GetDatum(agtv->val.float_value));

0 commit comments

Comments
 (0)