Calendar tables in PostgreSQL 9

前端 未结 3 1840
囚心锁ツ
囚心锁ツ 2021-01-04 06:07

I am building an analytics database (I have a firm understanding of the data and the business objectives and only basic-to-moderate database skills).

I have come acr

3条回答
  •  囚心锁ツ
    2021-01-04 06:42

    In PostgreSQL, you can generate calendar tables of arbitrary length and granularity on the fly:

    SELECT  CAST('2011-01-01' AS DATE) + (n || ' hour')::INTERVAL
    FROM    generate_series(0, 23) n
    

    This does not require recursion (as with the other systems) and is a preferred method to generate the volatile resultsets.

提交回复
热议问题