我很确定下面的查询曾经在Presto上为我工作:
select segment, sum(count)
from modeling_trends
where segment='2557172' and date = '2016-06-23' and count_time between '2016-06-23 14:00:00.000' and '2016-06-23 14:59:59.000';
group by 1;
现在当我运行它时(在EMR上的Presto 0.147上),我得到一个试图将varchar分配给日期/时间戳的错误。
我可以使用:
select segment, sum(count)
from modeling_trends
where segment='2557172' and date = cast('2016-06-23' as date) and count_time between cast('2016-06-23 14:00:00.000' as TIMESTAMP) and cast('2016-06-23 14:59:59.000' as TIMESTAMP)
group by segment;
但是感觉很脏…有更好的方法吗?
与其他数据库不同,Trino不会在varchar和其他类型之间自动转换,即使对于常量也是如此。强制转换可以工作,但更简单的方法是使用类型构造函数:
WHERE segment = '2557172'
AND date = date '2016-06-23'
AND count_time BETWEEN timestamp '2016-06-23 14:00:00.000' AND timestamp '2016-06-23 14:59:59.000'
您可以在这里看到各种类型的示例:https://trino.io/docs/current/language/types.html
只是一个快速的想法…你试过在约会中省略破折号吗?用20160623
代替2016-06-23
我在SQL server中遇到了类似的问题,但没有使用Presto。