gpt4 book ai didi

postgresql - Postgres递归json限制

转载 作者:行者123 更新时间:2023-11-29 12:08:02 24 4
gpt4 key购买 nike

引用 Postgresql jsonb traversal

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;

在末尾添加 limit 确实会限制返回,但似乎在检查每条记录的内部。

是否可以在 with 联合内进行限制?

此查询在大型数据集上受到严重影响。不过,我确实看到我可以限制平面选择中的时间戳范围。

最佳答案

如果您要限制行数,您应该在初始查询中添加 order bylimit,例如:

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/

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