Questions tagged «generate-series»

4
在PostgreSQL中生成两个日期之间的时间序列
我有这样的查询,它很好地生成了两个给定日期之间的一系列日期: select date '2004-03-07' + j - i as AllDate from generate_series(0, extract(doy from date '2004-03-07')::int - 1) as i, generate_series(0, extract(doy from date '2004-08-16')::int - 1) as j 它在2004-03-07和之间生成162个日期2004-08-16,这正是我想要的。该代码的问题在于,当两个日期来自不同年份时(例如,当我尝试使用2007-02-01和时),它将无法给出正确的答案2008-04-01。 有更好的解决方案吗?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.