sqlite3.ProgrammingError: You did not supply a value for binding 1

Viewed 865

I'm trying to load csv data into a database that I've already built, and am getting the above noted error. The CSV file only has 29 rows, everything is spelled correctly, I just don't know if I'm missing out on some small piece of syntax? Can anyone recommend how to resolve this or where I may be going wrong?

My function is detailed below:

def load_csv_to_db():
    db_file_name = 'records.db'
    csv_file_name = '13100262.csv'

    SQL = """
    insert into records_table (ref_date,geo,dguid,sex,age_group,student_response,uom,uom_id,scalar_factor,scalar_id,
    vector,coordinate,value,status,symbol,terminated,decimals) values (:ref_date,:geo,:dguid,:sex,:age_group,
    :student_response,:uom,:uom_id,:scalar_factor,:scalar_id,:vector,:coordinate,:value,:status,:symbol,:terminated,
    :decimals)"""

    with open(csv_file_name, 'rt') as csv_file:
        csv_reader = csv.DictReader(csv_file)

        with sq.connect(db_file_name) as conn:
            cursor = conn.cursor()
            cursor.executemany(SQL, csv_reader)
1 Answers

The first row of the spreadsheet does not contain a column whose contents are (the literal) "ref_date".

Since program is using DictReader, assume the first line of spreadsheet is column titles, which must exactly match the placeholder names used in the SQL (though not necessarily the order).

Related