I’m creating a Python script to insert some records in a table, but have the following problem:
INSERT INTO orders VALUES (7656940929251, "ADIDAS | KID'S STAN SMITH") ,(242345235233, 'ADIDAS | CLASSIC BACKPACK')
I get the error: “Invalid column name ‘ADIDAS | KID’S STAN SMITH’
How can I fix this with Python?
Advertisement
Answer
Let’s say this is your tuple:
tuples_v3s = ((7656941224163, 'ADIDAS | CLASSIC BACKPACK'),
             (7656941256931, 'ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR'),
             (7656940929251, "ADIDAS | KID'S STAN SMITH"))
for tuples_v3 in tuples_v3s:
  print(f"""INSERT INTO  orders VALUES ({tuples_v3[0]},'{tuples_v3[1].replace("'","''")}' ) """)
#INSERT INTO  orders VALUES (7656941224163,'ADIDAS | CLASSIC BACKPACK' ) 
#INSERT INTO  orders VALUES (7656941256931,'ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR' ) 
#INSERT INTO  orders VALUES (7656940929251,'ADIDAS | KID''S STAN SMITH' )