1

I am trying to enter data from a CSV file into an SQL database. The CSV file contains a variable recorded over time for several individuals. This is the table that I have setup:

cur.execute('''CREATE TABLE IF NOT EXISTS systolic
        (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        mask_id TEXT UNIQUE,
        systolic_id INTEGER,
        rz INTEGER, one_mon INTEGER, two_mon INTEGER, three_mon INTEGER,
        six_mon INTEGER, seven_mon INTEGER, twelve_mon INTEGER, fifteen_mon INTEGER,
        eighteen_mon INTEGER, twentyone_mon INTEGER, twentyfour_mon INTEGER,
        twentyseven_mon INTEGER, thirty_mon INTEGER, thirtythree_mon INTEGER,
        thirtysix_mon INTEGER, thirtynine_mon INTEGER, fortytwo_mon INTEGER,
        fortyfive_mon INTEGER, fortyeight_mon INTEGER, fiftyone_mon INTEGER)
        ''')

I want to iterate through rows of the CSV file and insert data from those rows into specific columns in the CSV file. I would like this program to read a value from a column in the CSV file, select a specific column in the SQL database based on the data in that row and insert the value from the row into the column. I wrote the following code, but it is not working. What is the correct way to do this?

cur.execute('INSERT OR IGNORE INTO systolic (mask_id, ?) VALUES (?,?)', (row['VISITCODE'], row['MASKID'],row['SBP'))

As you can see, I'm using python to create the database. Appreciate your help!

LfB
  • 17
  • 6

1 Answers1

-1

It looks like you're missing a closing bracket (]) after 'SBP'.

cur.execute('INSERT OR IGNORE INTO systolic (mask_id, ?) VALUES (?,?)', (row['VISITCODE'], row['MASKID'],row['SBP']))

Stacktrace
  • 112
  • 4