Fix some SQL quoting to work under postgresql