How do I generate a date series in PostgreSQL without hard coding the dates?
I want to generate a series of months. The start should be the first month of the current year, the stop is the current date with an interval of 1 month.


I would just keep it like d::date but you can format it however you want,

SELECT d::date, to_char(d, 'YYYYmm')
FROM generate_series(
  date_trunc('year', now())::timestamp without time zone,
  now()::timestamp without time zone,
  '1 month'
) AS gs(d);


But you can reformat it with to_char() if you want. 

For more information see How do I generate a date series in PostgreSQL?