Search Postgresql Archives

Options for complex materialized views sharing most of the same logic?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi guys, hope everyone's well. I'm in a situation that we find ourselves in a lot, and I'm wondering if there's an easier option.

I have one view which totals about 60 columns per day. Each day has a "days ago" column like so:

row_number() over (order by date desc) as days_back

Reason being is that there's not an entry every day, so it's useful. I then have four different views which do largely the same thing, totaling the days four different ways:

1) by last 10
2) by the last 30
3) by the last 60
4) by the entire year

Each of these views is basically a copy of one another for 99% of the code (the summing, percentages, etc). The only differences are:

1) checks the days_back <= 10
2) checks days_back <= 30
3) checks days_back <= 60
4) does not check days_back

Is there some easier way for me to maintain the structure of the view without copying/pasting it 4 times and making one small tweak? I find myself adding/removing columns to these views and I do it 4 times each time.

Thanks!

--

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux