1

我有一张桌子帖子:

      Column       |           Type           |                     Modifiers                      
-------------------+--------------------------+----------------------------------------------------
 body              | text                     | not null
 from              | character varying(2000)  | not null
 date              | timestamp with time zone | not null

我想计算一个用户一天有多少行,给定月份的每一天一行。

在 oracle 中,我将“生成”一个包含当前月份天数的表,然后将“日期”列与“生成”日期连接起来。

就像是

> select *
  2    from (select sysdate + level l from dual connect by level < 10)
  3  /

         L
----------
2013-06-07
2013-06-08
2013-06-09
2013-06-10
2013-06-11
2013-06-12
2013-06-13
2013-06-14
2013-06-15

9 rows selected.

postgres中有类似的东西吗?

4

1 回答 1

1

http://diethardsteiner.blogspot.com/2012/03/postgresql-auto-generating-sample.html

我只用一次谷歌搜索就找到了这个。你可以尝试使用它。

以防作者删除或网页被清除。

WITH date_series AS (
SELECT
   DATE(GENERATE_SERIES(DATE '2012-01-01', DATE '2012-01-10','1 day')) AS generateddate
)
SELECT 
      generateddate 
    , EXTRACT(DAY FROM generateddate) AS day
    , EXTRACT(MONTH FROM generateddate) AS month
    , EXTRACT(QUARTER FROM generateddate) AS quarter
    , EXTRACT(YEAR FROM generateddate) AS year
 FROM 
     date_series;
于 2013-06-07T20:11:52.483 回答