Database - the application of the function generate_series to query a period of time in postgresql

In daily development, it is often necessary to list all the time in a certain period of time. At this time, it is impossible to query from the existing tables in the database, and there may be confirmation. At this time, the function generate_series is used

 

Requirement: List all the months in 2019

SQL text:

select to_char(generate_series(date_trunc('month',to_date('20190101','yyyymmdd')),date_trunc('month',to_date('20191201','yyyymmdd')),'1 month'),'yyyymm') as yyyymm

The execution results are as follows:

Guess you like

Origin blog.csdn.net/dazhanglao/article/details/103458144