Re: Monetary Data Types Improvement

From: Erik Wienhold <ewie(at)ewie(dot)name>
To: b(dot)powell(dot)jr(at)outlook(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Monetary Data Types Improvement
Date: 2024-03-18 18:43:18
Message-ID: zemvbpqzow25zzltgs3f2d6gy7aebyago3chnw34446tzyqa7k@mksmtmt6nvxj
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Erik Wienhold 2024-03-18 18:45:08 Re: Monetary Data Types Improvement
Previous Message Erik Wienhold 2024-03-18 16:25:10 Re: Duplicates being removed from intarray on subtraction of another intarray