pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Monetary Data Types Improvement
8+ messages / 6 participants
[nested] [flat]

* Monetary Data Types Improvement
@ 2024-03-17 02:16 PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  0 siblings, 1 reply; 8+ messages in thread

From: PG Doc comments form @ 2024-03-17 02:16 UTC (permalink / raw)
  To: pgsql-docs@lists.postgresql.org; +Cc: b.powell.jr@outlook.com

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'.


^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
@ 2024-03-18 18:43 ` Erik Wienhold <ewie@ewie.name>
  2024-03-18 18:45   ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-18 22:24   ` Re: Monetary Data Types Improvement David Rowley <dgrowleyml@gmail.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Erik Wienhold @ 2024-03-18 18:43 UTC (permalink / raw)
  To: b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
@ 2024-03-18 18:45   ` Erik Wienhold <ewie@ewie.name>
  1 sibling, 0 replies; 8+ messages in thread

From: Erik Wienhold @ 2024-03-18 18:45 UTC (permalink / raw)
  To: b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org

I wrote:
> The attached patch does that.

Hit send to early.

-- 
Erik


Attachments:

  [text/plain] v1-0001-Add-note-about-missing-money-operators.patch (0B, ../../b4p3owrto6swwe6dvbtkdsvz3paoyusvq5la6waka2m3rmy5hk@vbokq6en57v2/2-v1-0001-Add-note-about-missing-money-operators.patch)
  download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
@ 2024-03-18 22:24   ` David Rowley <dgrowleyml@gmail.com>
  2024-03-20 14:58     ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  1 sibling, 1 reply; 8+ messages in thread

From: David Rowley @ 2024-03-18 22:24 UTC (permalink / raw)
  To: Erik Wienhold <ewie@ewie.name>; +Cc: b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org

On Tue, 19 Mar 2024 at 07:43, Erik Wienhold <ewie@ewie.name> wrote:
> 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.

My vote would go to adding a deprecation notice to that section of the
docs.  There's some talk [1] about how we discourage the usage of the
money type and that goes on to discuss the possibilities of moving it
into a contrib module.

My hope would be that deprecation notice would steer most people away
from using it and therefore reduce the number of questions about it
due to fewer new use cases of it.

David

[1] https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-18 22:24   ` Re: Monetary Data Types Improvement David Rowley <dgrowleyml@gmail.com>
@ 2024-03-20 14:58     ` Erik Wienhold <ewie@ewie.name>
  2024-03-20 15:07       ` Re: Monetary Data Types Improvement Dave Cramer <davecramer@postgres.rocks>
  0 siblings, 1 reply; 8+ messages in thread

From: Erik Wienhold @ 2024-03-20 14:58 UTC (permalink / raw)
  To: David Rowley <dgrowleyml@gmail.com>; +Cc: b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org

On 2024-03-18 23:24 +0100, David Rowley wrote:
> My vote would go to adding a deprecation notice to that section of the
> docs.  There's some talk [1] about how we discourage the usage of the
> money type and that goes on to discuss the possibilities of moving it
> into a contrib module.
> 
> My hope would be that deprecation notice would steer most people away
> from using it and therefore reduce the number of questions about it
> due to fewer new use cases of it.
> 
> [1] https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz

+1

Huh, I didn't know that it used to have a deprecation notice at some
point.  But that note was removed in 8.3:

https://www.postgresql.org/message-id/20071009123315.5fb283c1.darcy%40druid.net

-- 
Erik





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-18 22:24   ` Re: Monetary Data Types Improvement David Rowley <dgrowleyml@gmail.com>
  2024-03-20 14:58     ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
@ 2024-03-20 15:07       ` Dave Cramer <davecramer@postgres.rocks>
  2024-03-21 19:11         ` Re: Monetary Data Types Improvement Jonathan S. Katz <jkatz@postgresql.org>
  0 siblings, 1 reply; 8+ messages in thread

From: Dave Cramer @ 2024-03-20 15:07 UTC (permalink / raw)
  To: Erik Wienhold <ewie@ewie.name>; +Cc: David Rowley <dgrowleyml@gmail.com>; b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org

On Wed, 20 Mar 2024 at 10:59, Erik Wienhold <ewie@ewie.name> wrote:

> On 2024-03-18 23:24 +0100, David Rowley wrote:
> > My vote would go to adding a deprecation notice to that section of the
> > docs.  There's some talk [1] about how we discourage the usage of the
> > money type and that goes on to discuss the possibilities of moving it
> > into a contrib module.
> >
> > My hope would be that deprecation notice would steer most people away
> > from using it and therefore reduce the number of questions about it
> > due to fewer new use cases of it.
> >
> > [1] https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz
>
> +1
>
> Huh, I didn't know that it used to have a deprecation notice at some
> point.  But that note was removed in 8.3:
>
>
> https://www.postgresql.org/message-id/20071009123315.5fb283c1.darcy%40druid.net
>
>
Sadly that was a mistake. Money is not really a useful type.

Dave

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-18 22:24   ` Re: Monetary Data Types Improvement David Rowley <dgrowleyml@gmail.com>
  2024-03-20 14:58     ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-20 15:07       ` Re: Monetary Data Types Improvement Dave Cramer <davecramer@postgres.rocks>
@ 2024-03-21 19:11         ` Jonathan S. Katz <jkatz@postgresql.org>
  2024-03-22 03:17           ` RE: Monetary Data Types Improvement Brian Powell Jr <b.powell.jr@outlook.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Jonathan S. Katz @ 2024-03-21 19:11 UTC (permalink / raw)
  To: Dave Cramer <davecramer@postgres.rocks>; Erik Wienhold <ewie@ewie.name>; +Cc: David Rowley <dgrowleyml@gmail.com>; b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org

On 3/20/24 11:07 AM, Dave Cramer wrote:
> 
> 
> On Wed, 20 Mar 2024 at 10:59, Erik Wienhold <ewie@ewie.name 
> <mailto:ewie@ewie.name>> wrote:
> 
>     On 2024-03-18 23:24 +0100, David Rowley wrote:
>      > My vote would go to adding a deprecation notice to that section
>     of the
>      > docs.  There's some talk [1] about how we discourage the usage of the
>      > money type and that goes on to discuss the possibilities of moving it
>      > into a contrib module.
>      >
>      > My hope would be that deprecation notice would steer most people away
>      > from using it and therefore reduce the number of questions about it
>      > due to fewer new use cases of it.
>      >
>      > [1]
>     https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz
>     <https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz;
> 
>     +1
> 
>     Huh, I didn't know that it used to have a deprecation notice at some
>     point.  But that note was removed in 8.3:
> 
>     https://www.postgresql.org/message-id/20071009123315.5fb283c1.darcy%40druid.net <https://www.postgresql.org/message-id/20071009123315.5fb283c1.darcy%40druid.net;
> 
> 
> Sadly that was a mistake. Money is not really a useful type.

Here's[1] the latest "let's remove money" discussion (there's allegedly 
a hackers thread too, but I'm having trouble finding it.

+1 on reinstating the deprecation notice, given it'll be some years 
before we can fully remove it (at least based on the discussion).

Thanks,

Jonathan

[1] 
https://www.postgresql.org/message-id/flat/18240-c5da758d7dc1ecf0%40postgresql.org


Attachments:

  [application/pgp-signature] OpenPGP_signature.asc (839B, ../../e1ba1e0d-d067-48cf-b39f-978c91d5757d@postgresql.org/2-OpenPGP_signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* RE: Monetary Data Types Improvement
  2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
  2024-03-18 18:43 ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-18 22:24   ` Re: Monetary Data Types Improvement David Rowley <dgrowleyml@gmail.com>
  2024-03-20 14:58     ` Re: Monetary Data Types Improvement Erik Wienhold <ewie@ewie.name>
  2024-03-20 15:07       ` Re: Monetary Data Types Improvement Dave Cramer <davecramer@postgres.rocks>
  2024-03-21 19:11         ` Re: Monetary Data Types Improvement Jonathan S. Katz <jkatz@postgresql.org>
@ 2024-03-22 03:17           ` Brian Powell Jr <b.powell.jr@outlook.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Brian Powell Jr @ 2024-03-22 03:17 UTC (permalink / raw)
  To: Jonathan S. Katz <jkatz@postgresql.org>; Dave Cramer <davecramer@postgres.rocks>; Erik Wienhold <ewie@ewie.name>; +Cc: David Rowley <dgrowleyml@gmail.com>; pgsql-docs@lists.postgresql.org <pgsql-docs@lists.postgresql.org>

Coming from using SQL Server, money was the easiest way I saw to replicate FORMAT(<value>,'C2') for reporting purposes but then I guess I could have just cast it as money for the report/view. Beyond that, using NUMERIC(<num>,2) works fine.

Brian Powell Jr, EI

-----Original Message-----
From: Jonathan S. Katz <jkatz@postgresql.org> 
Sent: Thursday, March 21, 2024 3:12 PM
To: Dave Cramer <davecramer@postgres.rocks>; Erik Wienhold <ewie@ewie.name>
Cc: David Rowley <dgrowleyml@gmail.com>; b.powell.jr@outlook.com; pgsql-docs@lists.postgresql.org
Subject: Re: Monetary Data Types Improvement

On 3/20/24 11:07 AM, Dave Cramer wrote:
> 
> 
> On Wed, 20 Mar 2024 at 10:59, Erik Wienhold <ewie@ewie.name 
> <mailto:ewie@ewie.name>> wrote:
> 
>     On 2024-03-18 23:24 +0100, David Rowley wrote:
>      > My vote would go to adding a deprecation notice to that section
>     of the
>      > docs.  There's some talk [1] about how we discourage the usage of the
>      > money type and that goes on to discuss the possibilities of moving it
>      > into a contrib module.
>      >
>      > My hope would be that deprecation notice would steer most people away
>      > from using it and therefore reduce the number of questions about it
>      > due to fewer new use cases of it.
>      >
>      > [1]
>     https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz
>     
> <https://www.postgresql.org/message-id/ZXgh74Ykj3iWvXKr@paquier.xyz;
> 
>     +1
> 
>     Huh, I didn't know that it used to have a deprecation notice at some
>     point.  But that note was removed in 8.3:
> 
>     
> https://www.postgresql.org/message-id/20071009123315.5fb283c1.darcy%40
> druid.net 
> <https://www.postgresql.org/message-id/20071009123315.5fb283c1.darcy%4
> 0druid.net>
> 
> 
> Sadly that was a mistake. Money is not really a useful type.

Here's[1] the latest "let's remove money" discussion (there's allegedly a hackers thread too, but I'm having trouble finding it.

+1 on reinstating the deprecation notice, given it'll be some years
before we can fully remove it (at least based on the discussion).

Thanks,

Jonathan

[1] 
https://www.postgresql.org/message-id/flat/18240-c5da758d7dc1ecf0%40postgresql.org


^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2024-03-22 03:17 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-17 02:16 Monetary Data Types Improvement PG Doc comments form <noreply@postgresql.org>
2024-03-18 18:43 ` Erik Wienhold <ewie@ewie.name>
2024-03-18 18:45   ` Erik Wienhold <ewie@ewie.name>
2024-03-18 22:24   ` David Rowley <dgrowleyml@gmail.com>
2024-03-20 14:58     ` Erik Wienhold <ewie@ewie.name>
2024-03-20 15:07       ` Dave Cramer <davecramer@postgres.rocks>
2024-03-21 19:11         ` Jonathan S. Katz <jkatz@postgresql.org>
2024-03-22 03:17           ` Brian Powell Jr <b.powell.jr@outlook.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox