UNION ALL 参数化 postgres
UNION ALL parameterised postgres
我想在 postgres 中做这样的事情
select * from table t where t.one = 11 AND t.two = 12 and t.three = 13
union all
select * from table t where t.one = 21 AND t.two = 22 and t.three = 23
我尝试了 join lateral
和 inner join
,但是性能太差了。所以我需要 union all
这些查询,但我不想只是连接不确定数量的这些值,postgres 有类似这些 的东西吗?
我认为根本不需要 UNION。而且我不明白 JOIN 在这里有什么帮助
您的查询相当于:
select *
from table t
where (t.one,t.two,t.three) in ( (11,12,13), (21,22,23) );
或者您可以尝试加入 VALUES 子句:
select t.*
from table t
join (
values (11,12,13), (21,22,23)
) as x(c1,c2,c3) on t.one = x.c1
and t.two = x.c2
and t.three = x.c3;
我想在 postgres 中做这样的事情
select * from table t where t.one = 11 AND t.two = 12 and t.three = 13
union all
select * from table t where t.one = 21 AND t.two = 22 and t.three = 23
我尝试了 join lateral
和 inner join
,但是性能太差了。所以我需要 union all
这些查询,但我不想只是连接不确定数量的这些值,postgres 有类似这些 的东西吗?
我认为根本不需要 UNION。而且我不明白 JOIN 在这里有什么帮助
您的查询相当于:
select *
from table t
where (t.one,t.two,t.three) in ( (11,12,13), (21,22,23) );
或者您可以尝试加入 VALUES 子句:
select t.*
from table t
join (
values (11,12,13), (21,22,23)
) as x(c1,c2,c3) on t.one = x.c1
and t.two = x.c2
and t.three = x.c3;