ERROR: SELECT DISTINCTではORDER BYの式はSELECTリスト内になければなりません

エラーが出た。

これは order by で指定している列が select distinct で使われていない場合に発生する。
今回は以下のクエリでエラーになった。

select distinct to_char(log_date, 'YYYY-MM') from point_log where id = 15544 order by log_date desc limit 25;

これは log_date が select distinct で使われていないため。
to_char のような関数で使ってもダメなようですね・・・。

ということで、以下のように修正。

select distinct to_char(log_date, 'YYYY-MM') as test from point_log where id = 15544 order by test desc limit 25;

to_char() を test という列名にすればOK。