[英]How to query postgres to get data in json format?
From the table I want to select users firstname and lastname only if their age is greater than 10 in a json format. 我要从表中选择仅以json格式年龄超过10岁的用户的名字和姓氏。
So the output of the query should be 因此查询的输出应为
I could select create a json text from but not sure how to apply where clause for Key = 'AGE' and value > 10
我可以选择从中创建一个json文本,但不确定如何为
Key = 'AGE' and value > 10
应用where子句
Here is my query 这是我的查询
select json_object_agg(key,value) from table where key in ('firstname','lastname')
Add an aggregate with a FILTER
clause: 添加带有
FILTER
子句的聚合:
SELECT id,
json_object_agg(key, value) AS json,
FROM mytable
GROUP BY id
HAVING (max(value::integer) FILTER (WHERE key = 'AGE')) > 10;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.