The following query works in MySQL:
SELECT
f.created_date as time_sec
,sum(f.value) as value
, date_format( f.created_date , '%a') as metric
FROM ck_view_fills as f
GROUP BY date_format(f.created_date, '%a' )
I have migrated my database to PostgreSQL and I am now converting my queries to match. My naive conversion looks like this:
SELECT
f.created_date as time_sec
,sum(f.value) as value
, to_char( f.created_date , "D") as metric
FROM ck_view_fills as f
GROUP BY to_char( f.created_date , "D")
This query is not accepted and the error message produced by PostgreSQL is the following:
Error in query (7): ERROR: column "f.created_date" must appear in the GROUP BY clause or be used in an aggregate function LINE 2: f.created_date as time_sec
As far as I can tell f.created_date is indeed used in the group by clause. I have also seen examples using this very syntax. So what is the cause of this error and how do I get around it?