Fix SQL query to work w/ postgres