Fixed errors while inserting data.

Some queries fail in PG 9.3 because they are not properly escaped.