【问题标题】:How to extract epoch from date in Redshift如何从 Redshift 中的日期中提取纪元
【发布时间】:2018-09-27 00:25:26
【问题描述】:

AWS 的 Redshift 提供了extract function

EXTRACT ( datepart FROM { TIMESTAMP 'literal' | timestamp } )

datepart 采用 various values 包括 epoch - 因此您可以从 timestamp 中提取纪元,例如

select extract(epoch from {timestamp_column_name});

是否可以从日期字段中提取历元?

select extract(epoch from {date_column_name});

如果不是,如何将日期字段转换为时间戳?

select extract(epoch from {expression to convert {date_column_name} to timestamp});

【问题讨论】:

  • "将日期字段转换为时间戳" - date_column::timestamp?
  • 是的,这很方便。如果我这样做timestamp_column::timestamp 会发生什么。可以对datetimestamp 列使用相同的查询吗?
  • 你试过extract(epoch from date_column::timestamp)吗?

标签: sql amazon-redshift epoch


【解决方案1】:

是否可以从日期字段中提取纪元?是的

Select extract(epoch from getdate()::date)

【讨论】:

  • getdate 函数返回 timestamp 类型而不是 date 类型的文档链接:docs.aws.amazon.com/redshift/latest/dg/r_GETDATE.html
  • @mattgathu 我相信 getdate() 不是你的专栏,这只是一个例子......你总是可以使用 :: date 进行隐蔽
  • 我知道您可以在 timestamp 字段中使用 extract epoch。但是文档不清楚是否可以从date 字段中使用extract epoch。这是我的问题。
猜你喜欢
  • 2015-08-21
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-24
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多