cockroachdb / cockroachdb/cockroach
jsonpath: correctly scan keys with a numeric starting character
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
When using JSONPath queries with keys that begin with a numeric character, CockroachDB fails to parse them, even when the key is clearly a string and not a numeric literal. This diverges from Postgres, which correctly interprets the key.
Explicitly, this includes handling edge cases like "2e", which resembles scientific notation but should be treated as a string key.
Currently, we're able to work around this problem by quoting the key names (ex. `$."2e"`).
Postgres:
```
norman=# select '$.2e'::jsonpath;
ERROR: 42601: invalid floating point number at or near "2e" of jsonpath input
LINE 1: select '$.2e'::jsonpath;
^
LOCATION: jsonpath_yyerror, jsonpath_scan.l:294
Time: 1.421 ms
norman=# select '$.2ee'::jsonpath;
jsonpath
----------
$."2ee"
(1 row)
Time: 1.056 ms
norman=# select '$.2f'::jsonpath;
jsonpath
----------
$."2f"
(1 row)
```
Cockroach:
```
demo@127.0.0.1:26257/demoapp/defaultdb> select '$.2e'::jsonpath;
ERROR: could not parse "$.2e" as type jsonpath: at or near "invalid floating point literal": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
$.2e
^
demo@127.0.0.1:26257/demoapp/defaultdb> select '$.2ee'::jsonpath;
ERROR: could not parse "$.2ee" as type jsonpath: at or near "invalid floating point literal": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
$.2ee
^
demo@127.0.0.1:26257/demoapp/defaultdb> select '$.2f'::jsonpath;
ERROR: could not parse "$.2f" as type jsonpath: at or near "trailing junk after numeric literal at or near "2f"": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
$.2f
^
```
Jira issue: CRDB-49294
Contributor guide
Assessment
This issue has not been assessed yet.