gpt4 book ai didi

json - postgresql to_json() 用法,转换为列作为键值json

转载 作者:行者123 更新时间:2023-11-29 11:52:01 26 4
gpt4 key购买 nike

我正在尝试在 postgresql 中完成以下操作

我的表结构是

postgres=# select * from t_test;
var1 | var2 | var3
------+------+------
1 | A | v1
1 | B | v2
2 | A | u1

我希望输出按 var1 分组。 var2 和 var3 必须成为 json 键值。像这样:

 var1 |  result
------+------------
1 | { A: v1, B: v2 }
2 | { A: u1 }

我无法从文档中清楚地理解 to_json 函数。有人可以帮忙吗?

最佳答案

他们说 select to_json(table_name.*) 可能有效

关于json - postgresql to_json() 用法,转换为列作为键值json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24884044/

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