我有一个表格帖子:
Column | Type | Modifiers
-------------------+--------------------------+----------------------------------------------------
body | text | not null
from | character varying(2000) | not null
date | timestamp with time zone | not null
我想计算用户一天中有多少行,一个月内每天一行。
在oracle中,我会“生成”一个表,其中包含当前月份的天数,然后将“date”列与“生成”日期一起加入。
像
这样的东西> 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中有类似内容吗?
答案 0 :(得分: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;