Usa DISTINCT ON :
SELECT DISTINCT ON (contenthash)
id,
contenthash,
filesize,
to_timestamp(timecreated) :: DATE
FROM mdl_files
ORDER BY contenthash, timecreated, id;
DISTINCT ON è un'estensione Postgres che fa in modo che restituisca una riga per ogni combinazione univoca delle chiavi tra parentesi. La riga specifica è la prima trovata in base a order by clausola.