taosdata / TDengine

High-performance, scalable time-series database designed for Industrial IoT (IIoT) scenarios
https://tdengine.com
GNU Affero General Public License v3.0
23.45k stars 4.87k forks source link

Feature Request: Support for DECIMAL Data Type (e.g., DECIMAL(40,18)) in TDengine for High-Precision Financial Data #27147

Closed sky93 closed 3 months ago

sky93 commented 3 months ago

Is your feature request related to a problem? Please describe.
I'm using TDengine to store and analyze large-scale cryptocurrency data. My use case involves tracking and calculating financial metrics like cryptocurrency prices, transaction amounts, and market capitalizations, which require extremely high precision. However, I am always frustrated when I encounter inaccuracies due to the limitations of the FLOAT data type in TDengine. The lack of a DECIMAL data type to handle large numbers with fine precision makes it difficult to accurately represent financial data, leading to potential rounding errors and imprecise calculations.

Describe your desired behavior
I want TDengine to support a DECIMAL data type, similar to MySQL's DECIMAL(p,s), which would allow me to store and process numbers with high precision and large scale (e.g., DECIMAL(40,18)). This would enable TDengine to accurately handle financial data, ensuring that calculations involving cryptocurrencies and other financial metrics are precise and reliable.

Describe your solutions/suggestions if you've any
I suggest implementing a DECIMAL data type within TDengine that supports user-defined precision and scale. This data type should use fixed-point arithmetic to avoid the inaccuracies inherent in floating-point representations. The flexibility to define precision (e.g., 40 digits) and scale (e.g., 18 decimal places) would make TDengine a powerful tool for financial applications, allowing for accurate storage and computation of values like cryptocurrency prices, trading volumes, and market capitalizations.

Additional context
In the cryptocurrency industry, precision is non-negotiable. A minor error in representing a value could lead to significant financial discrepancies. For example, Bitcoin prices may have up to 8 decimal places, and some altcoins even more. Without a DECIMAL type, it's challenging to manage this data accurately in TDengine. Implementing this feature would significantly expand TDengine's applicability in financial sectors and increase its competitive edge against databases like MySQL, which already provide this capability.

CREATE TABLE crypto_data (
    timestamp TIMESTAMP,
    symbol VARCHAR(10),
    price DECIMAL(40,18),
    volume DECIMAL(40,18)
);

INSERT INTO crypto_data VALUES ('2020-12-20 23:30:31', 'BTC', 23845.123456789012345678, 10.123456789012345678);
yu285 commented 3 months ago

we are going to support DECIMAL in the future ,thanks for your advice