I have a program that reads financial data in JSON and inserts it into an SQLite database. The problem is when I’m inserting it into SQLite numeric column and it doesn’t seem to like the decimal object.
I’ve found this question answered before, but the answer is outdated and from what I understand SQLite now has a currency data type called numeric.
Right now as a workaround I’m storing decimal values as text, but is it possible to store it as numeric? Am I stuck with the overhead of converting decimals to strings and vice versa for database inserts and financial calculations?
sqlite3allows you to register an adapter (to transparently convertDecimalstoTEXTwhen inserting) and a converter (to transparently convertTEXTintoDecimalswhen fetching).The following is a lightly modified version of the example code from the docs:
yields