Adjust SQL to work correctly with PostGres.