fix broken query on postgres