Re: Monetary Data Types Improvement

Поиск
Список
Период
Сортировка
От Erik Wienhold
Тема Re: Monetary Data Types Improvement
Дата
Msg-id zemvbpqzow25zzltgs3f2d6gy7aebyago3chnw34446tzyqa7k@mksmtmt6nvxj
обсуждение исходный текст
Ответ на Monetary Data Types Improvement  (PG Doc comments form <noreply@postgresql.org>)
Ответы Re: Monetary Data Types Improvement  (Erik Wienhold <ewie@ewie.name>)
Re: Monetary Data Types Improvement  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-docs
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



В списке pgsql-docs по дате отправления:

Предыдущее
От: Erik Wienhold
Дата:
Сообщение: Re: Duplicates being removed from intarray on subtraction of another intarray
Следующее
От: Erik Wienhold
Дата:
Сообщение: Re: Monetary Data Types Improvement