Skip to main content

使用 @db.Money

Optimize 提供建议,帮助你识别和解决由 @db.Money 类型引起的性能问题。

¥Optimize provides recommendations to help you identify and resolve performance issues caused by the use of @db.Money type.

以下模型使用 @db.Money 原生类型:

¥The following model uses the @db.Money native type:

model Item {
// ...
price Decimal @db.Money
// ...
}

问题是什么?

¥What is the problem?

PostgreSQL 中的 @db.Money 数据类型并不适合存储货币值。在内部,@db.Money 实现为整数,这提供了速度,但缺乏灵活性。它以意想不到的方式处理小数值和舍入,这可能导致不准确。

¥The @db.Money data type in PostgreSQL is not ideal for storing monetary values. Internally, @db.Money is implemented as an integer, which offers speed but lacks flexibility. It handles fractional values and rounding in unexpected ways, which can lead to inaccuracies.

此外,@db.Money 类型不存储任何与货币相关的信息。相反,它依赖于全局 lc_monetary 语言环境设置,这可能并不适合所有用例。

¥Additionally, the @db.Money type does not store any information about the associated currency. Instead, it relies on the global lc_monetary locale setting, which may not be suitable for all use cases.

更多信息,请参阅 PostgreSQL 文档

¥For more information, refer to the PostgreSQL documentation.