如何创建日期列表

时间:2018-06-07 16:04:10

标签: amazon-redshift

我使用下面的代码生成epoch中的日期列表。但是,我希望列表中的最新日期等于unix_timestamp()的值。

-- generate list of id's
with t1 as
(
select row_number() over (order by order_id) as n from orders 
limit 2000 
),
-- generate date based on incremental id's
t2 as 
(select 
  (getdate() - n+1) as date 
 from t1
)
  select 
    extract(epoch from date) as date
  from t2 
  where t2.date >= '2014-01-01'
  order by date desc

我不知道如何将此列表中的最后一个值设为unix_timestamp()

1 个答案:

答案 0 :(得分:0)

使用提取物引用时代

xder= [0, 0]

使用date_part

没有引号
select extract('epoch' from timestamp date) as date
from t2 
where t2.date >= '2014-01-01'
order by date desc