Trying to group on date parts - Mailing list pgsql-novice

From Rob Anderson
Subject Trying to group on date parts
Date
Msg-id FHEPJNONMOLHMPDJDOCMEEDAHIAA.roba@bml.uk.com
Whole thread Raw
Responses Re: Trying to group on date parts  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
I am trying to select items from a file and to group on the CCYY-MM part of
the date, in order to give a total count of items for that period

SELECT
    SUBSTRING(mylog.datetime,1,7) AS datetime,
    count(*) as counter
FROM mylog
WHERE mylog.datetime<'2005-02-02'
GROUP BY SUBSTRING(mylog.datetime,1,7)
ORDER BY mylog.datetime;

However I get the error message

ERROR:  column "mylog.datetime" must appear in the GROUP BY clause or be
used in an aggregate function

I have also used date_trunc('month', mylog.datetime) with the same error

Help!!!!



pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: VACUUM and other maintenance work
Next
From: "Keith Worthington"
Date:
Subject: Calling trigger function from a function