0


I have the following python code which is part of a larger for loop, where I am inserting latlon data along with weather data for future inspection. Note that I am checking if the data at that iteration is float64 (since it could also be masked, where I'd rather skip).

values = (lat_db,lon_db,sst_db)
        if type(sst_db) != numpy.float64:
            continue

        c.executemany('INSERT INTO current VALUES(?,?,?)',values)

The table itself was created through these lines:

conn = sqlite3.connect('sst.db')
c = conn.cursor()

# Create the database table.
c.execute('''CREATE TABLE current
             (lat real, lon real, sst real)''')

Upon running my script, I get the following error:

    c.executemany('INSERT INTO current VALUES(?,?,?)',values)
ValueError: parameters are of unsupported type

1 Answer 1

2

execute expects a sequence of parameters.

executemany works for multiple executions, so it expects a sequence of sequences of parameters:

values = ((lat_db,lon_db,sst_db),)
c.executemany('INSERT INTO current VALUES(?,?,?)',values)

This makes sense only if you want to insert multiple records:

values = ((lat_db1, lon_db1, sst_db1),
          (lat_db2, lon_db2, sst_db2))
c.executemany('INSERT INTO current VALUES(?,?,?)', values)
Sign up to request clarification or add additional context in comments.

4 Comments

should I adapt my create table statement to have float instead of real values?
This has nothing to do with the declared column type, which has no effect anyway. You are supposed to execute the code shown before trying to use float64 values together with the sqlite3 module.
I have done the changes, but the error persists. I have also changed the create table statement just to be sure, same thing.
Sorry, float64 already is compatible by default. The error was raised because lat_db is not a sequence.

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.