Sql 博士后及;Rust R2D2:如何在不使用转义双引号的情况下将数组_to_json作为文本/字符串获取?

Sql 博士后及;Rust R2D2:如何在不使用转义双引号的情况下将数组_to_json作为文本/字符串获取?,sql,postgresql,rust,postgresql-9.5,rust-cargo,Sql,Postgresql,Rust,Postgresql 9.5,Rust Cargo,我有以下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)::t

我有以下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}]
然而,在我的rust应用程序使用r2d2_postgres时,我得到了一个转义字符串:

"[{\"username\":\"Bobby\",\"notifications\":0}]"
防锈代码:

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!(“{}”,值)
如果您想打印不带引号的值。

不相关,但是:
数组到json(数组到json(t))
可以简化为
json到agg(t))
甚至
json到agg(t)
@a\u没有名字的马
json-agg(t)
在每个项目之间放置一个
\n
json\u agg(row\u to\u json(t))
我认为这似乎还不错。不过,对于那些好奇的人来说,原来的转义字符串问题仍然存在。
jsonb_agg(t)
不会添加新字符串lines@a_horse_with_no_name谢谢,很高兴知道。我将继续使用它。现在只需要解决转义的双引号问题。引号仅在打印期间转义。它们不会在记忆中消失。使用
println!(“{}”,值)如果要打印不带引号的值。