From: raf <raf@raf.org>
To: pgsql-general@lists.postgresql.org
Subject: Re: Implement a new data type
Date: Wed, 12 Aug 2020 10:01:26 +1000
Message-ID: <20200812000126.6ofbn4z7mrtee3ir@raf.org> (raw)
In-Reply-To: <CAALojA__cLQag+VkvXr0CXq4fDiSyDziDjSCHNwk4Dt3VUQ3oA@mail.gmail.com>
References: <PR3PR01MB69704C1002BC9916D3E11B58E0450@PR3PR01MB6970.eurprd01.prod.exchangelabs.com>
<CAFj8pRCdxsrOmrxgm5ZaUA-EkDJat=ZHxeHst8uS0cBnuXCdLA@mail.gmail.com>
<CAALojA__cLQag+VkvXr0CXq4fDiSyDziDjSCHNwk4Dt3VUQ3oA@mail.gmail.com>
On Tue, Aug 11, 2020 at 06:38:39AM -0700, Miles Elam <miles.elam@productops.com> wrote:
> Also of note: PostgreSQL already has a money type (
> https://www.postgresql.org/docs/current/datatype-money.html)
> But you shouldn't use it (
> https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_money).
>
> I only bring it up so that you can know to make your money type a slightly
> different name to avoid a conflict. Money is deceptively hard to implement
> correctly. I'd recommend reading the second link if you have not already to
> avoid previously known issues.
I use decimal(10,2) for whole cents, and decimal(12,6)
for sub-cents. Single currency only. I didn't know
there was a money type originally, but it wouldn't be
usable for me anyway without the ability to specify the
scale and precision.
I recommend considering passing values to the database
as "decimal '1.23'" rather than bare numeric literals,
just so there's no chance of the value being
interpreted as a float at any stage by postgres. Maybe
that's being too paranoid but that's a good idea when
it comes to money. :-)
Perhaps the incorporation of currency would make a new
money type interesting. Currencies probably don't
change as often as timezones but there would probably
still be some ongoing need for updates.
cheers,
raf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: raf@raf.org
Subject: Re: Implement a new data type
In-Reply-To: <20200812000126.6ofbn4z7mrtee3ir@raf.org>
References: <PR3PR01MB69704C1002BC9916D3E11B58E0450@PR3PR01MB6970.eurprd01.prod.exchangelabs.com> <CAFj8pRCdxsrOmrxgm5ZaUA-EkDJat=ZHxeHst8uS0cBnuXCdLA@mail.gmail.com> <CAALojA__cLQag+VkvXr0CXq4fDiSyDziDjSCHNwk4Dt3VUQ3oA@mail.gmail.com> <20200812000126.6ofbn4z7mrtee3ir@raf.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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