I have this main table (year 2010):
Serial | Day_start | Data
-----------|-----------|--------
1 |1262304000 | data1
2 | epoch | data2
3 | epoch | data3
4 | [...] | .
5 | epoch | .
6 | epoch | .
7 | epoch | .
[...] | epoch | .
365 |1293753600 | .
366 | epoch |
Where Serial
corresponds to the day of the year.
Serial: 1 -> 1/jan/2010 -> 1262304000
I want to create a view, where the first column of this view extracts the day-month from the epoch of this table.
CREATE OR REPLACE VIEW year_2010 AS
SELECT row_number() OVER (ORDER BY "MainTable".Day_start) AS index,
"MainTable".Day_start,
"MainTable".Data
FROM "MainTable"
WHERE "MainTable".Day_start >= 1262304000 AND "MainTable".Day_start <= 1293753600;
With this SQL I create a view using the column Day_start
as Index. Each, for each year. This table contains 8 Years of data (that's why I do not use the "Serial".
How do I extract the day-month from the epoch and rebuild the view? I can't find the function I would need from here: https://www.postgresql.org/docs/9.1/static/functions-datetime.html
The generated view should be:
Index(date)| Data(double precision)
-----------|--------
01-01 | data1
02-01 | data2
03-01 | data3
04-01 | .
[...] | .
06-11 | .
07-11 | .
[...] | .
31-12 | .
01-01 |