[英]How to extract day/month/year etc from varchar date field, using Presto?
I currently have tables with dates, set up as VARCHAR in the format of YYYY-MM-DD such as:我目前有带日期的表,以 YYYY-MM-DD 格式设置为 VARCHAR,例如:
2017-01-01
The date column I'm working with is called 'event_dt'我正在使用的日期列称为“event_dt”
I'm used to being able to use day(event_dt), month(event_dt), year(event_dt)
etc. in Hive, but Presto just gives me error executing query
with no other explanation when the queries fail.我习惯于在 Hive 中使用
day(event_dt), month(event_dt), year(event_dt)
等,但是当查询失败时,Presto 只是给我error executing query
而没有其他解释。
So, for example, I've tried:因此,例如,我尝试过:
select
month(event_dt)
from
my_sql_table
where
event_dt = '2017-01-01'
I would expect the output to read:我希望 output 能够读取:
01
but all I get is [Code: 0, SQL State: ] Error executing query
但我得到的只是
[Code: 0, SQL State: ] Error executing query
I've tried a few other methods listed in the Presto documentation but am having no luck at all.我尝试了 Presto 文档中列出的其他一些方法,但完全没有运气。 I realize this is probably very simple but any help would be much appreciated.
我意识到这可能非常简单,但任何帮助将不胜感激。
Thanks to @LukStorms in the comments to the original question, I've found two solutions:感谢@LukStorms 在对原始问题的评论中,我找到了两个解决方案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.