Best Data Type to Store Prices with 8 Decimals in SQLite

datatypesmoneysqlite

I am developing a trading system which stores data in SQLite, consisting of OHLC and volume. I would also like to store some indicators like RSI etc I read the other answer which indicated integers as the data type. In my case I am looking at 8 digit precision which would slow down the calculations if I were to multiply every value by 1e8 Any recommendations are appreciated!

Best Answer

The FAQ pretty much explains the reason why you don't want to use their REAL data type for storing numbers with 8 decimal places.

(16) Why does ROUND(9.95,1) return 9.9 instead of 10.0? Shouldn't 9.95 round up?

https://www.sqlite.org/faq.html#q16

Workaround 1

The trick of using an INTEGER to achieve your required level of precision has been used since computers existed.

With today's powerful CPUs, I wouldn't worry about the overhead of any additional calculations. You'll need to run benchmarks to (dis)prove my statement.

Workaround 2

IMHO - You shouldn't use a tool that doesn't support your requirements.