[英]Unable to create a large json object from a postgreSQL query using json_build_object
I am trying to create a json object from my query using json_build_object as follows:我正在尝试使用 json_build_object 从我的查询中创建一个 json 对象,如下所示:
Select json_agg(json_build_object('first_name',first_name,
'last_name',last_name,
'email',email,
'date_joined',date_joined,
'verification_date',verification_date,
'zip_code',zip_code,
'city',city,
'country',country))
from users
WHERE last_name= 'xyz'
The json object builds fine with above shown number of columns however when i add all column names, the query gets stuck/hung indefinitely and no error message is displayed. json 对象使用上面显示的列数构建得很好,但是当我添加所有列名时,查询会无限期地卡住/挂起,并且不会显示任何错误消息。 I reduce the number of columns in the query and it returns a proper json object.
我减少了查询中的列数,并返回一个正确的 json 对象。 Does anyone have any idea about this?
有没有人对此有任何想法? Thanks
谢谢
I also tried the query after omitting json_agg but still the same result在省略 json_agg 后我也尝试了查询,但结果仍然相同
I am not sure why your query hangs - could be that there is a limit on the number of args - but since you are building each JSON object in a trivial way (attribute names are the same as column names), try using row_to_json
like this:我不确定为什么您的查询挂起 - 可能是 args 的数量有限制 - 但由于您正在以一种简单的方式构建每个 JSON 对象(属性名称与列名称相同),请尝试使用
row_to_json
像这样:
select json_agg(row_to_json(u.*)) from users u WHERE last_name = 'xyz';
Having tens or hundreds of args is not nice anyway.无论如何,拥有数十或数百个参数并不好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.