gpt4 book ai didi

sql - Postgres和Rust R2D2 : How to get array_to_json as text/string without the escaped double quotes?

转载 作者:行者123 更新时间:2023-12-03 11:36:15 25 4
gpt4 key购买 nike

我有以下SQL:

select jsonb_agg(t) 
from (
select username, notifications
from useraccountview where username = 'Bobby'
) t;
这在PSQL中为我提供了以下内容:
[{"username":"Bobby","notifications":0}]
当我放入 ::text时:
select jsonb_agg(t)::text 
from (
select username, notifications
from useraccountview where username = 'Bobby'
) t;
我仍然得到相同的:
[{"username":"Bobby","notifications":0}]
但是在使用r2d2_postgres的rust应用程序方面,我得到了一个转义的字符串:
"[{\"username\":\"Bobby\",\"notifications\":0}]"
rust 代码:
let qr = conn.query("select jsonb_agg(t)::text from (select username, notifications from useraccount where username = $1) t",&[&param]).unwrap();
let value: &str = qr[0].get(0);
println!("{:?}",value);
输出:
"[{\"username\":\"Bobby\",\"notifications\":0}]"
如何防止双引号转义?

最佳答案

报价仅在打印过程中转义。它们不会在内存中逃脱。如果要打印不带引号的值,请使用println!("{}", value);

关于sql - Postgres和Rust R2D2 : How to get array_to_json as text/string without the escaped double quotes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65880030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com