1

I'm writing SQL with python and sqlite.

I have a python list called supermarket_ids and each element of the list is a number: 2.

I also have a column in a sqlite table which stores INTEGER or NUMERIC. I use a for loop to loop the list and insert to sqlite database.

I INSERT the variable to the column, but when I SELECT it from the table, it returns b'\x02\x00\x00\x00\x00\x00\x00\x00' instead of 2.

I tried to alter the column to store either INTEGER or NUMERIC but it is still the same.

My code for INSERT is as follows:

c.execute("INSERT INTO SKU_Table (Supermarket_ID) VALUES (?)", (supermarket_ids[i]))

And when I view it with a database software called DB Browser for SQLite, it shows that the Supermarket_ID is now a BLOB.

Any idea?

enter image description here

5
  • Show the code that inserts the value. Commented Mar 2, 2018 at 18:06
  • 1
    I have already showed the code, is there anymore I need to show? Commented Mar 5, 2018 at 2:27
  • 1
    Show the code that creates the supermarket_ids items. Commented Mar 5, 2018 at 7:50
  • 1
    This happens, if you use numpy/pandas-types. Convert to int(v) before inserting, then it works. Commented May 25, 2020 at 10:30
  • I think this could be duplicate of the question in this link: stackoverflow.com/questions/49456158/…. Commented Feb 3, 2021 at 6:35

0

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.