fixed SQL Statements to be postgres compatible