0

I generated this array I want to insert into my table using python sql.

def get_guards(list3, list2, list1):
       merg_list = [(list3[i], list2[i], list1[i]) for i in range(0, len(list3))] 
       return merg_list
qs = """INSERT INTO duties (token, post, service_no) VALUES (%s, %s, %s)"""
list1 = group_guards
list2 = zns
list3 = token_no
values = get_guards(list3, list2, list1)
cur.executemany(qs, values)
conn.commit()

This gives me an error

pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')

The list output is

[('GUARD_NO:0002', 'Gate A', ['09494947', '209944']), ('GUARD_NO:0002', 'Guard B', ['38394904', '44774887', '8494994']), ('GUARD_NO:0002', 'Guard C', ['8764884', 'B909876'])]
2
  • Do you want to insert ['09494947', '209944'] into service_no? Commented Feb 27, 2020 at 13:02
  • @vaeng yes.I want to insert in a table 'duties' with columns token, post, and service_no. In my case Guard_no:0002 is token, Gate A is post and '09494947', '209944' -service_no: ( guards for post Gate A) Commented Feb 28, 2020 at 7:00

1 Answer 1

1

As vaeng infers: It seems that you want to add a list

['09494947', '209944']

to service_no. SQL is not very keen in lists in the python format. So you would have to either split your lines and add a separate entry for each value of service_no or normalize it and add the foreign key to a different table. for each service_no .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.