我有一个包含字符串术语的Postgresql JSON 2D数组列,例如:
输入
[["edwards", "block", "row"], ["edwards"], ["block"]]
是否可以纯粹在Postgresql中计算每个术语的出现次数? e.g:
输出
Terms, Occur
["edwards", "block", "row"] [2,2,1]
(或以某种类似的格式)。或者我是否必须使用编程语言计算出现次数?
答案 0 :(得分:1)
这是一个解决方案:
select array_to_json(array(
select json_array_length(a.value)
from json_array_elements('[["edwards", "block", "row"], ["edwards"], ["block"]]'::json) a
));
答案 1 :(得分:0)
最终想出这个。查询如下:
SELECT COUNT(t), t
FROM (SELECT jsonb_array_elements_text(json->'named_entities') AS t
FROM tweets WHERE event_id = XX) AS t1
GROUP BY t