【问题标题】:Are there limitation on converting or casting timestamp column to time in redshift database without timezone?在没有时区的红移数据库中将时间戳列转换或转换为时间是否有限制?
【发布时间】:2016-10-10 12:56:05
【问题描述】:

我正在使用 Postgresql 处理 Amazon Redshift 数据库。我有一个时间戳列,我需要将其转换为时间。我使用以下行来确定列属性:

select * from pg_table_def where tablename = 'tableA'

这一行详细说明了时间戳列的类型是“没有时区的时间戳”。

为了在 Postgresql 中测试转换方法,我尝试了以下行:

select '2016-10-01 12:12:12'::time

将时间戳转换为'12:12:12'

我想为表中的整个“时间戳”列重新创建它,但是当我运行以下行时遇到以下错误:

select timestamp::time from tableA

'SQL Error [500310] [0A000]: [Amazon](500310) Invalid operation: Specified types or functions (one per INFO message) not supported on Redshift tables.;

对于没有时区的时间戳列是否有限制将它们转换为时间?

我做错了什么,列的每条记录都没有转换为时间?

--编辑-- @halil 这是我从你那里使用的修改后的行。

select (extract(hour from timestamp) || ':' || extract(minute from timestamp) || ':' || extract(second from timestamp)) as my_time from tableA

--编辑-- @halil 这里是用于减去时间戳的行。我所做的只是从前一个时间戳中减去下一个时间戳:

select eventtimestamp - lead(eventtimestamp) over (order by eventtimestamp)
from ga_visit_events 

【问题讨论】:

  • 是 Redshift 还是 Postgres? Redshift 是基于这样一个旧版本的 Postgres,以至于这两者已经不再相同了。
  • 它的红移,我在红移中使用 postgresql
  • 没有“使用 postgres in redshift”。这是一个或另一个。不能两者兼有。
  • 那时我正在使用redshift。

标签: amazon-redshift


【解决方案1】:

我检查了 redshift 文档,但找不到合适的函数来执行此操作。 但是你可以使用这个查询来得到你想要的

select date_part(h, your_tm)||':'||date_part(min, your_tm)||':'||date_part(sec, your_tm) from your_table

【讨论】:

  • 我一直在使用修改版本,见编辑。但是我遇到的问题是我需要及时使用数学函数,在这种情况下只是简单的减法。因此,当我们使用您的行或我的行时,该列将转换为文本。在这种情况下,我不能用它做任何事情。
  • 你为什么不对时间戳做数学运算并稍后将它们转换为字符串?
  • 我已经对时间戳进行了数学计算,但它给了我非常糟糕的结果,例如参见上面的时间戳减法编辑。我得到的结果看起来像这样:“4511137 years 4 mons -00:00:10.184”
猜你喜欢
  • 2017-04-25
  • 2018-12-18
  • 1970-01-01
  • 2015-10-16
  • 2021-06-25
  • 2021-09-06
  • 2021-01-05
  • 2019-06-29
  • 1970-01-01
相关资源
最近更新 更多