Range generation in PostgreSQL
06 Apr 2019Generating ranges in PostgreSQL can be a very useful tool for the creation of virtual tables to join to. Should your report require you to generate an entire range; left joining only to the values that need to be filled out.
The following code snippet will allow you to generate such a range:
This snippet will create a table of dates, 1st of each month for the year 2018.
The initial line of the CTE allows you to set the start of the range:
The frequency at which the range is sampled is then set with this line:
Finally, the end of the range is set with the following line: