Generate a Series of Dates in YSQL

The generate_series YugabyteDB SQL built-in function is a set returning function in that it can return more than one row.

It comes in handly when you need to generate a series of integers.

Example:

				
					yugabyte=# SELECT gs FROM generate_series(1, 10) gs;
 gs
----
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
(10 rows)
				
			

But the generate_series function isn’t limited to a series of integers; it can also generate a series of dates!

Example:

				
					yugabyte=# SELECT g::DATE FROM generate_series(current_date, current_date+9, '1 Day') g;
     g
------------
 2023-03-03
 2023-03-04
 2023-03-05
 2023-03-06
 2023-03-07
 2023-03-08
 2023-03-09
 2023-03-10
 2023-03-11
 2023-03-12
(10 rows)
				
			

Have Fun!

Was going to go for a swim...