0

The below sample query leads to "row value misused" error. I am just not able to figure out the problem. My intent is to extract all records where "ISIN" matches "Test1" and "Test2".

Environment: Python 3.10.0 Windows 21H1

import sqlite3 as objSQLite

# Connect
objDatabase = objSQLite.connect("Sample.db")
objCursor = objDatabase.cursor()

# Create table
objCursor.execute("create table if not exists ScripData(ISIN text);")

# Add rows
objCursor.execute("insert or ignore into ScripData values(?)", ("Test1", ))
objCursor.execute("insert or ignore into ScripData values(?)", ("Test2", ))
objCursor.execute("insert or ignore into ScripData values(?)", ("Test3", ))
objCursor.execute("insert or ignore into ScripData values(?)", ("Test4", ))

objDatabase.commit()

# Query
objCursor.execute("select * from ScripData where ISIN=(?,?)", ("Test1", "Test2", ))
arrResult = objCursor.fetchall()
print(arrResult)

Error is:

Traceback (most recent call last):
  File "Query.py", line 19, in <module>
    objCursor.execute("select * from ScripData where ISIN=(?,?)", ("Test1", "Test2", ))
sqlite3.OperationalError: row value misused

1 Answer 1

1

You can't use = to find matches for multiple values, you need to use IN.

objCursor.execute("select * from ScripData where ISIN IN (?,?)", ("Test1", "Test2" ))
arrResult = objCursor.fetchall()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! So silly to miss my database basics.

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.