cockroachdb / cockroachdb/cockroach
Incompatible implementation of `json_to_record` functions
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
The function `json_to_record` and friends behave differently in CockroachDB than they do in Postgres.
PostgreSQL allows you to extract any field of an object as a scalar value of type `json`, but CockroachDB does not allow string-fields to be extracted as a value of type `json`.
**To Reproduce**
On cockroachdb:
```
psql (16.0, server 13.0.0)
Type "help" for help.
defaultdb=> select t.* from json_to_record('{"field1":"string value", "field2":{"object":"value"}}') as t(field1 json, field2 json);
ERROR: could not parse JSON: unable to decode JSON: while decoding 12 bytes at offset 0:
...|string value|...
...|^...........|...: invalid JSON token
defaultdb=> select t.* from json_to_record('{"field1":"string value", "field2":{"object":"value"}}') as t(field1 text, field2 json);
field1 | field2
--------------+---------------------
string value | {"object": "value"}
(1 row)
defaultdb=>
```
**Expected behavior**
On Postgres
```
postgres=# select t.* from json_to_record('{"field1":"string value", "field2":{"object":"value"}}') as t(field1 json, field2 json);
field1 | field2
----------------+--------------------
"string value" | {"object":"value"}
(1 row)
```
**Additional data / screenshots**
Environment:
```
defaultdb=> select version();
version
--------------------------------------------------------------------------------------
CockroachDB CCL v23.1.10 (x86_64-pc-linux-gnu, built 2023/09/14 14:09:38, go1.19.10)
(1 row)
```
Jira issue: CRDB-35301
Contributor guide
Assessment
This issue has not been assessed yet.