【发布时间】:2019-10-01 18:43:22
【问题描述】:
我正在编写一个查询来获取按 created_at 分组的记录,下面是我的查询。
$q = Post::where('user_id', '=', auth()->user()->id)
->orderBy('created_at', 'desc')
->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"))
->take(10)
->get(array(
DB::raw('Date(created_at) as date'),
DB::raw('COUNT(id) as "views"')
))->reverse()
这在 mysql 上运行没有任何错误,但是当我使用 postgresql 在 heroku 上推送代码时,我得到错误:
ERROR: function date_format(timestamp without time zone, unknown) does not exist
【问题讨论】:
-
是否应该在 MySQL 和 PostgreSQL 上运行相同的代码?
标签: laravel postgresql eloquent