类型时间戳记的无效输入语法:"NOW()-INTERVAL '12 hours'" [英] Invalid input syntax for type timestamp: "NOW() - INTERVAL '12 hours'"
本文介绍了类型时间戳记的无效输入语法:"NOW()-INTERVAL '12 hours'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据``时间''字段进行查询以获取上周的数据:
I'm trying to make a query based on a field ``time` to get the last week data:
Measure::where('time', '>', "NOW() - INTERVAL '12 hours'")->get();
但我无法使其正常工作.
but I can't make it work.
I get this message:
SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type timestamp: "NOW() - INTERVAL '12 hours'" (SQL: select * from "measures" where "time" > NOW() - INTERVAL '12 hours')
我是从官方文档中获得此条件的的timescaleDB,应该与postgres兼容:
Thing is I get this condition from official docs of timescaleDB, supposed to be postgres compatible:
从时间>的条件中选择COUNT(*).NOW()-间隔'12小时";
SELECT COUNT(*) FROM conditions WHERE time > NOW() - INTERVAL '12 hours';
为什么会发生,我该怎么办?
Why is it happening, and what should I do ?
推荐答案
我认为您需要使用whereRaw,因为表达式中包含函数调用.
I think you need to use whereRaw because you have function calls in your expression.
Measure::whereRaw("time > NOW() - INTERVAL '12 hours'")->get();
这篇关于类型时间戳记的无效输入语法:"NOW()-INTERVAL '12 hours'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文