I have to do a union of a large number of disjoint daily tables from 2012-12-17 to 2012-10-30 in this example. The code for this gets ugly here is the snippet:
CREATE table map
with (appendonly=true, compresstype = quicklz)
AS
SELECT * FROM final_map_12_17
UNION ALL
SELECT * FROM final_map_12_16
UNION ALL
SELECT * FROM final_map_12_15
UNION ALL
SELECT * FROM final_map_12_14
UNION ALL
....
SELECT * FROM final_map_10_30;
Can I do this type of thing with a sequence or PL/PGSQL function instead of writing out each individual select by hand?
You can loop over date range in plpgsql function like this:
Calling the function:
is equivalent to: