Due to the presence of " ' " in the data that is being inserted into the PostgreSQL database, an error occurs. The error is as follows:
psycopg2.ProgrammingError: syntax error at or near "S" LINE 1: ...ice_type) VALUES('7055598', 'CHEE KONG POI', 'HEE'S ENGINEER...
Is there a way around this problem? The current code is as follows:
def store(license_number, individual_name, corporate_name, reg_address, email_address, land_line, hand_phone_line, work_type):
statement = (
"INSERT INTO service_reviews_serviceprovider" \
" (license_number, individual_name, corporate_name, reg_address, email_address, land_line, hand_phone_line, service_type)" \
" VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', 'electrician');"
).format(license_number, individual_name, corporate_name, reg_address, email_address, land_line, hand_phone_line)
print(statement)
cur.execute(statement)
cur.connection.commit()
return None