I feel like this should be very straightforward, but I cannot seem to find a solution.
I am trying to create a plpgsql function that takes as input a start date and an end date, that then generates a series of years between the two dates that I can use as columns for my new table.
For example, if I call
my_function('2010-01-01', '2015-01-1')
I want a new table with columns 2010, 2011, 2012, 2013, 2014, and 2015.
I'm inclined to use the generate_series() function to do this, but I cannot figure out how to actually store the values it returns and pull them out to create my table with.
I'm using Postgres 9.5.3