Skip to content
Advertisement

Select all the years from a range without having a years table

I have selected the current year with

SELECT EXTRACT(YEAR FROM NOW()) as value

I want to print a list of all the years from 1990 to the current year without having to create a table of the list of years, is there a way to do it or I must create a table to do this?

Advertisement

Answer

select generate_series(1990, (extract(year from now()))::int) as value;

or

select value from generate_series(1990, (extract(year from now()))::int) as value;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement