我想根据参数从不同的表中进行选择,可以这样做吗?两个表都具有兼容的结构。
select * from
(
case when p_target then
select * from table_a
else
select * from table_b
end
);
尽管这根本不是最佳实践,您应该真正查看您的数据模型,但这里有一种方法:
with table_a as (
select 1::int, 'a'::text param
), table_b as (
select 2::int, 'b'::text param
)
select *
from (
select *
from table_a
union all
select *
from table_b
) rs
where param = 'a'
只需向所有表添加一个参数列,将它们联合起来,然后将它们全部放在一个子查询中,您可以从中选择特定表的参数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句