with recursive flat (id, timestamp, path, value)
as (select id, timestamp, key, value
from trending_snapshot, jsonb_each(snapshot)
union select f.id, f.timestamp, j.key, j.value
from flat f, jsonb_each(f.value) j
where jsonb_typeof(f.value) = 'object' )
select timestamp, path, (value->>'value')::float AS value
from flat
where path like any(array['%Run01TubingPressure'])
limit 12;
在末尾添加限制确实限制了返回,但似乎在每个记录都被检查了。
是否可以在 with union 内部进行限制?
此查询在大型数据集上会受到严重影响。 不过,我确实看到我可以限制平面选择中的时间戳范围。
最佳答案
如果您要限制行数,则应在初始查询中添加 order by
和 limit
,例如:
with recursive flat (id, timestamp, path, value) as (
(select id, timestamp, key, value
from trending_snapshot,
jsonb_each(snapshot)
order by id
limit 12)
union all
select f.id, f.timestamp, j.key, j.value
from flat f,
jsonb_each(f.value) j
where jsonb_typeof(f.value) = 'object' )
select timestamp, path, (value->>'value')::float AS value
from flat
where path like any(array['%Run01TubingPressure'])
或额外的 where
子句(在初始查询中)根据条件过滤行。
关于postgresql - Postgres 递归 json 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51448628/