I need to store a DiffTime
from the time
library in a database (PostgreSQL) and have three options for converting to a database type:
我需要将时间库中的DiffTime存储在数据库(PostgreSQL)中,并且有三个选项可以转换为数据库类型:
- Integer using
fromIntegral . fromEnum
- 整数使用fromIntegral。 fromEnum
- Numeric via Rational
toRational
- 通过Rational toRational的数字
- Real using
realToFrac
- 真正使用realToFrac
The integer is exact, but rather large, since stored in pico seconds (10^12). Numeric is also exact, but it is potentially very expensive to calculate a Rational
, since it has to calculate gcd
for numerator and denominator. The real is inexact, but maybe that doesn't matter.
整数是精确的,但相当大,因为存储在皮秒(10 ^ 12)。数值也是精确的,但计算一个Rational可能非常昂贵,因为它必须计算分子和分母的gcd。真实是不准确的,但也许这无关紧要。
My time granularity would never be below minutes or larger than a couple of days. I need to make exact calculations. Speed is probably not an issue.
我的时间粒度绝不会低于几分钟或大于几天。我需要做出精确的计算。速度可能不是问题。
Which option should I choose and what are the implications? Should Rational generally be avoided when handling user submitted numbers like explained in scientific
library?
我应该选择哪个选项以及含义是什么?在处理用户提交的数字时,一般应该避免Rational,如科学库中所解释的那样吗