I have the following SQL:
select jsonb_agg(t) from ( select username, notifications from useraccountview where username = 'Bobby' ) t;
This gives me following in PSQL:
[{"username":"Bobby","notifications":0}]
When I put a ::text
:
select jsonb_agg(t)::text from ( select username, notifications from useraccountview where username = 'Bobby' ) t;
I still get the same:
[{"username":"Bobby","notifications":0}]
However on my rust app’s side using r2d2_postgres, I get an escaped string instead:
"[{"username":"Bobby","notifications":0}]"
Rust code:
let qr = conn.query("select jsonb_agg(t)::text from (select username, notifications from useraccount where username = $1) t",&[¶m]).unwrap(); let value: &str = qr[0].get(0); println!("{:?}",value);
Outputs:
"[{"username":"Bobby","notifications":0}]"
How I can I prevent the escaping of double quotes?
Advertisement
Answer
The quotes are only escaped during printing. They are not escaped in memory. Use println!("{}", value);
if you want to print the value without the quotes.