【发布时间】:2020-11-13 08:27:21
【问题描述】:
我正在尝试根据字段“时间”进行查询以获取上周数据:
Measure::where('time', '>', "NOW() - INTERVAL '12 hours'")->get();
但我不能让它工作。
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 的official docs 得到这个条件,应该是 postgres 兼容的:
SELECT COUNT(*) FROM 条件 WHERE 时间 > NOW() - INTERVAL '12 小时';
为什么会这样,我该怎么办?
【问题讨论】:
-
time列的数据类型是什么? -
postgres 中的时间戳
-
我认为问题出在双引号上,尝试在没有双引号的情况下使用单引号的转义字符编写 12 小时。
标签: laravel postgresql eloquent timescaledb