Postgresql 为什么我的postgres横向子查询失败?
我尝试使用postgres对横向子查询的支持运行以下查询:Postgresql 为什么我的postgres横向子查询失败?,postgresql,lateral-join,Postgresql,Lateral Join,我尝试使用postgres对横向子查询的支持运行以下查询: with s as ( select tagValues ->> 'mode' as metric , array_agg(id) as ids from metric_v3.v_series where name = 'node_cpu' group by
with s as
(
select
tagValues ->> 'mode' as metric
, array_agg(id) as ids
from
metric_v3.v_series
where
name = 'node_cpu'
group by 1
)
select
t.starttime
, s.metric
, t.max
from
s, lateral (
select
d.starttime
, max(d.max) as max
from
metric_v3.gaugedata d
where
d.starttime >= '2020-01-17T00:00Z' AND d.starttime < '2020-01-24T00:00Z'
and d.seriesid in s.ids
group by 1
) t
order by 1,2;
我尝试了不同的横向查询方法,但我总是得到相同的错误。我不知道我错过了什么
如果运行CTE表达式并从中选择s*,则会得到预期的结果,因此该部件工作正常
我正在CentOS上运行Postgres 11.6。您不能在中使用数组。您需要使用
ANY
操作符:
and d.seriesid = any(s.ids)
and d.seriesid = any(s.ids)