The topic of 'how to store numpy' in sqlite has been discussed a couple of times. I think there are mainly two solutions:
- Store as BLOB without numpy dataframe, requires np.frombuffer(data, dtype=np.type); as described here: https://assorted-experience.blogspot.com/2013/12/store-numpy-arrays-in-sqlite.html
- Store as BLOB with numpy dataframe, register suitable adapter/converter; as described here: Python insert numpy array into sqlite3 database
Now let us suppose the numpy array is huge and only a slice of it is needed from the database. What is the best approach to select and retrieve the sliced data?
SELECT substr(data,start,length)
This will work for as long as data is BLOB and the numpy type np.int/uint8 was stored without the numpy data frame into BLOB. What about other data types such as np.uint64?
Of course, it is possible to store the numpy type in the sqlite database, too. Then any sliced-data request would need to adapt the SELECT request and the start/length information accordingly, i.e., scale it by the number of bytes of the respective data type.
Is there a better way to do this?