0

So i have a query like this in postgres

select a,b,c,d from table a where date between '2020-01-01' and '2021-01-01' 
union all
select a,b,c,d from table b where date between '2020-01-01' and '2021-01-01' 
union all
select a,b,c,d from table c where date between '2020-01-01' and '2021-01-01' 

How can i declare i parameter with the dates so that i only have to fill them out once?

something like this

declare d1 as date, d2 as date
set d1 as '2020-01-01'
set d2 as '2021-01-01'

select a,b,c,d from table1 a where date between d1 and d2
union all
select a,b,c,d from table2 a where date between d1 and d2
union all
select a,b,c,d from table3 a where date between d1 and d2 
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
user2210516
  • 407
  • 3
  • 8
  • 23

0 Answers0