Python Forum
Insert list in particular column! Help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert list in particular column! Help!
#1
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).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  store all variable values into list and insert to sql_summary table mg24 3 1,131 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  Sqllite column insert nickzsche 2 1,522 Jan-06-2022, 11:45 PM
Last Post: lucasbazan
  Not able to add extra column to the list in the python shantanu97 2 1,648 Nov-17-2021, 10:14 AM
Last Post: snippsat
  openpyxl insert list with formulas Irv1n 1 1,549 Sep-16-2021, 08:10 AM
Last Post: Irv1n
  Sort List of Lists by Column Nju 1 11,171 Apr-13-2021, 11:59 PM
Last Post: bowlofred
Lightbulb Insert a new column for Key Value brunolelli 0 1,493 Mar-20-2021, 03:27 PM
Last Post: brunolelli
  Space between list and column alignment rturus 8 5,095 Mar-17-2021, 04:47 PM
Last Post: rturus
  Get Value from List to Show in DataFrame Column ahmedwaqas92 1 1,897 Jun-22-2020, 08:24 AM
Last Post: ahmedwaqas92
  list comprehension : print column as row pyseeker 4 3,646 Sep-05-2019, 05:40 AM
Last Post: pyseeker
  Inserting a python list into a dataframe column wise mahmoud899 0 4,266 Mar-04-2019, 11:44 PM
Last Post: mahmoud899

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020