I'm trying to fill daily data for missing dates and can not find an answer, please help.
My daily_table
example:
url | timestamp_gmt | visitors | hits | other..
-------------------+---------------+----------+-------+-------
www.domain.com/1 | 2016-04-12 | 1231 | 23423 |
www.domain.com/1 | 2016-04-13 | 1374 | 26482 |
www.domain.com/1 | 2016-04-17 | 1262 | 21493 |
www.domain.com/2 | 2016-05-09 | 2345 | 35471 |
Expected result: I wand to fill this table with data for every domain and every day which just copy data from previous date
:
url | timestamp_gmt | visitors | hits | other..
-------------------+---------------+----------+-------+-------
www.domain.com/1 | 2016-04-12 | 1231 | 23423 |
www.domain.com/1 | 2016-04-13 | 1374 | 26482 |
www.domain.com/1 | 2016-04-14 | 1374 | 26482 | <-added
www.domain.com/1 | 2016-04-15 | 1374 | 26482 | <-added
www.domain.com/1 | 2016-04-16 | 1374 | 26482 | <-added
www.domain.com/1 | 2016-04-17 | 1262 | 21493 |
www.domain.com/2 | 2016-05-09 | 2345 | 35471 |
I can move a part of the logic into php, but it is undesirable, because my table has billions of missing dates.
SUMMARY:
During a few last days I foud out that:
- Amazon-redshift works with 8-th version of PostgreSql, that's why it does not support such a beautiful command like
JOIN LATERAL
- Redshift also does not support
generate_series
andCTEs
- But it supports simple
WITH
(thank you @systemjack) butWITH RECURSIVE
does not