Python Forum

Full Version: Insert list in particular column! Help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! I have a table 'employee' with data and with one empty column 'employee_department'.

[Image: bBx2CK]

I want to insert a list into this column. List contains integers:
depart_id_list = [3, 3, 3, 3, 4, 4, 3, 3, 2, 2, 2, ...]
I did the following:
for d in depart_id_list:
    cur.execute("INSERT INTO employee(employee_department) VALUES (%s)", [d])
But this is error. It seems to me that the logic of my query is that I insert "horizontally", and not "vertically", and all the missing values ​​are filled with null:
Error:
cur.execute("INSERT INTO employee(employee_department) VALUES (%s)", [d]) psycopg2.IntegrityError: null value in column "first_name" violates not-null constraint DETAIL: Failing row contains (1, null, null, null, null, null, null, 3).