我很确定以下查询曾经在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;
Run Code Online (Sandbox Code Playgroud)
现在,当我运行它(在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;
Run Code Online (Sandbox Code Playgroud)
但感觉很脏......有没有更好的方法呢?
Dav*_*ips 58
与其他一些数据库不同,Presto不会自动在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'
Run Code Online (Sandbox Code Playgroud)
您可以在此处查看各种类型的示例:https://prestodb.io/docs/current/language/types.html
| 归档时间: |
|
| 查看次数: |
41683 次 |
| 最近记录: |