You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if you read a JSON column from CockroachDB into a String field of a struct with query_as! macro (or query_as function) it reads incorrect data, adding a space (one \u{1} character) in the beginning of the JSON string representation.
Create a table in CockroachDB: CREATE TABLE IF NOT EXISTS data( tags JSON NOT NULL );
Create a row with a valid JSON dictionary in the table: INSERT INTO data (tags) VALUES('{"a":"1"}'::json);. Other types of JSON documents are also affected (arrays, 'null', etc.)
(Optional) check that the JSON is correct in the database with psql/dBeaver/...
Use sqlx to read this JSON into a String field:
pubstructData{pubtags:String,}let rows = sqlx::query_as!(Data,r#"SELECT tags as "tags: String" FROM data"#).fetch_all(&self.db_pool).await?;
Observe incorrect JSON: Data { tags: "\u{1}{\"a\": \"1\"}" }
P.S. PostgreSQL is not affected.
P.P.S. Using sqlx::Json to work with JSON fields solves this issue.
SQLx version
0.8.3
Enabled SQLx features
runtime-tokio,postgres,json
Database server and version
CockroachDB v24.3.3 (from Docker Hub)
Operating system
Linux,MacOS
Rust version
1.84.0, 1.86.0-nightly
The text was updated successfully, but these errors were encountered:
I have found these related issues/pull requests
this bug seems to not be reported before
Description
if you read a JSON column from CockroachDB into a String field of a struct with query_as! macro (or query_as function) it reads incorrect data, adding a space (one
\u{1}
character) in the beginning of the JSON string representation.Reproduction steps
I created a repo with a reproducible example, feel free to check it out: https://github.com/reflechant/sqlx-json-cockroach-bug
Steps to reproduce:
CREATE TABLE IF NOT EXISTS data( tags JSON NOT NULL );
INSERT INTO data (tags) VALUES('{"a":"1"}'::json);
. Other types of JSON documents are also affected (arrays, 'null', etc.)Data { tags: "\u{1}{\"a\": \"1\"}" }
P.S. PostgreSQL is not affected.
P.P.S. Using sqlx::Json to work with JSON fields solves this issue.
SQLx version
0.8.3
Enabled SQLx features
runtime-tokio,postgres,json
Database server and version
CockroachDB v24.3.3 (from Docker Hub)
Operating system
Linux,MacOS
Rust version
1.84.0, 1.86.0-nightly
The text was updated successfully, but these errors were encountered: