【发布时间】:2014-01-15 17:42:36
【问题描述】:
Postgres 9.1 - 我有一个按月“分区”表的模式(每个月都会创建一个新表,所有列都相同)。它没有设置为具有“主”表的正常分区。我目前正在编写一个相当大的查询,我每个月都必须运行几次。
架构:augmented_events
表:p201301(2013 年 1 月)p201302(2013 年 2 月)p201303(2013 年 3 月)
...p201312(2013 年 12 月)p201401(2014 年 1 月)
现在我必须将我的(简化的)查询写成:
select *
from augmented_events.p201301
union
select *
from augmented_events.p201302
union
select *
from augmented_events.p201303
union
select *
from augmented_events.p201312
union
select *
from augmented_events.p201401
每个月我都需要在新的月份添加。我想让它更具可扩展性,而不必每个月都重新访问它。是否有一个我可以创建(或存在)的函数循环遍历augmented_events 架构中的每个表,并将其视为合并这些表?
【问题讨论】:
标签: sql postgresql plpgsql partitioning dynamic-sql