I need to insert a specific range of years and months into a table so I can relate some climate data to those dates. Just like the table bellow:
| year | month |
|---|---|
| 1961 | 1 |
| 1961 | 2 |
| 1961 | 3 |
| 1961 | ... |
| 1961 | 12 |
| ... | ... |
| 2019 | 12 |
I am a beginner to SQL so i'm having a hard time coding this. I'm using VSC connected to a PostgresSQL Server. Can anyone help me?
I tried searching for a sollution here in stackoverflow but couldn't find it.
You can use a combination of generate_series() and extract():
Just set your start and end date (the timestamp) correct and generate_series() creates the entire list. Extract() gives you the year and the month.