On 2024-03-17 03:16 +0100, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/14/datatype-money.html > Description: > > It's not explicitly obvious that money doesn't behave like a normal numeric > type in that executing a procedure with a negative numeric value for money > causes an error. The solution to this is to pass the value as a string. For > example, -15.99 for money should be expressed as '-15.99'.
I assume it's intended to be used like other numeric datatypes (although with known issues[1]) given that this page does not mention any operations besides division. I see no reason why unary minus and even unary plus shouldn't be implemented if negative amounts are already possible. Maybe it's not worth the effort if one can just do (OP x::numeric)::money for any unary numeric operator OP instead. CREATE OPERATOR is another option. Maybe add a note like: "Money does not implement all operators that one might expect of a numeric type. For example, use (-amount::money::numeric)::money to negate amount." That would also fit nicely with the existing examples on casting to numeric and float8. The attached patch does that. [1] https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_money -- Erik