Postgresql – Generate all years between two timestamps
As part of a larger Postgres query, I generate all years between two given timestamps (timestamptz): select to_char(generate_series, 'YYYY') from generate_series( '2022-06-14 11:00:00.000+00'::timestamptz, '2023-06-14 11:00:00.000+00'::timestamptz, '1 year' ); Which returns: '2022' '2023' The issue is, if there is less than…