I have a column utc_time
where stores unix timestamp,
and I want to group by date,
But got errors.
def self.memory_info_daily(test_id=1)
self.unscoped
.where{ name =~ 'MemoryInfo' }
.where{ sony_alarm_test_id.eq(test_id)}
.group("to_char(to_timestamp(utc_time), 'YYYY-MM-DD')")
But it works by append .count
in the end of query.
Error
SELECT "sony_alarm_logs".* FROM "sony_alarm_logs" WHERE "sony_alarm_logs"."name" ILIKE 'MemoryInfo' AND "sony_alarm_logs"."sony_alarm_test_id" = 1 GROUP BY to_char(to_timestamp(utc_time), 'YYYY-MM-DD')
E, [2014-06-27T16:17:14.379965 #29797] ERROR -- : PG::GroupingError: ERROR: column "sony_alarm_logs.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "sony_alarm_logs".* FROM "sony_alarm_logs" WHERE "so...
^