ERROR: syntax error at or near "AND" LINE 2: AND t.section_id = AND TO_CHAR(t.sdate, 'YYYY')::in... ^ERROR: syntax error at or near "ORDER" LINE 14: ORDER BY sdate DESC LIMIT 18 OFFSET 0 ^