问题
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')
Thing is I get this condition from official docs of timescaleDB, supposed to be postgres compatible:
SELECT COUNT(*) FROM conditions WHERE time > NOW() - INTERVAL '12 hours';
Why is it happening, and what should I do ?
回答1:
I think you need to use whereRaw because you have function calls in your expression.
Measure::whereRaw("time > NOW() - INTERVAL '12 hours'")->get();
回答2:
Try hour
without quotes
SELECT COUNT(*) FROM conditions WHERE time > NOW() - INTERVAL 12 hour;
来源:https://stackoverflow.com/questions/63057183/invalid-input-syntax-for-type-timestamp-now-interval-12-hours