cockroachdb / cockroachdb/cockroach

sql/jsonpath: `jsonb_path_query` with `like_regex` gives inconsistent result with PG

Open
#154,589 1 comment 0 reactions 0 assignees View on GitHub
branch-master C-bug E-quick-win T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Same table in both PG and CRDB:

```sql
CREATE TABLE json_tab (
a INT PRIMARY KEY,
b JSONB
);

INSERT INTO json_tab VALUES
(1, '{"a": "b"}'),
(2, '[1,2,3,4, "foo"]'),
(3, '{"a": {"b": "c", "d": "e"}}'),
(4, '{"a": {"b": [1, 2, 3, 4]}}'),
(5, '{"a": {}}'),
(6, '{"a": {"b": {"c": "d"}, "d": "e"}}'),
(7, '{"a": [{"b": {"x": "y"}}, {"b": "e"}]}'),
(8, '{"a": [{"b":[]}]}'),
(9, '{"a": {"b": "c"}}'),
(10, '{"a": {"d": "e"}}');
```

PG:
```
> select a, jsonb_path_query(b, '$.a.b like_regex "hi.*"') FROM json_tab;

a | jsonb_path_query
----+------------------
1 | false
2 | false
3 | false
4 | null
5 | false
6 | null
7 | null
8 | false
9 | false
10 | false
```

CRDB:
```
a | jsonb_path_query
-----+-------------------
1 | null
2 | null
3 | false
4 | null
5 | null
6 | null
7 | null
8 | false
9 | false
10 | null
```

Even the given expression doesn't match any rows in both tables, the false or null are returned differently for different json value. We need to fix this case.

Jira issue: CRDB-55010

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.