Jul*_*oro 5 postgresql laravel eloquent timescaledb
I have this query in Laravel Eloquent:
$measures = Measure::groupBy('time')
->selectRaw('time, sum("delta") as sum_delta, sum("redistributed") as sum_redistr')
->where('operation_id', 'ACC0000001')
->where('time', '>', '2020-05-09 00:00')
->where('time', '<', '2020-05-10 00:00')
->where('source', 'source1')
->where('conso_prod', 'Conso')
->get()
Run Code Online (Sandbox Code Playgroud)
When I debug using toSql() function, and then I paste it into pgAdmin, I get the correct result.
select time, sum("delta") as sum_delta, sum("redistributed") as sum_redistr from "measures"
where "operation_id" = 'ACC0000001'
and "time" > '2020-05-09' and "time" < '2020-05-10' and "source" = 'source1' and "conso_prod" = 'Conso' group by "time"
Run Code Online (Sandbox Code Playgroud)
And I have a result each 30m which is correct.
But when I use eloquent, I have the same amount of rows, but all the time fields are the same:
"2020-05-09 00:00"
Run Code Online (Sandbox Code Playgroud)
instead of incrementing.
我不明白为什么?我使用带有 TimescaleDB 扩展的 PostgreSQL。
在我的模型中,我把时间投入到date而不是datetime
protected $casts = [
'time' => 'date'
];
Run Code Online (Sandbox Code Playgroud)
我把它改为:
protected $casts = [
'time' => 'datetime'
];
Run Code Online (Sandbox Code Playgroud)
它奏效了。
如果有人像我一样失败,我就让它在那里!还是要谢谢你的帮助
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |