Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5eD5-0001pL-R2 for pgsql-general@arkaria.postgresql.org; Wed, 12 Aug 2020 00:01:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5eD3-0006w3-Ev for pgsql-general@arkaria.postgresql.org; Wed, 12 Aug 2020 00:01:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5eD3-0006vv-6p for pgsql-general@lists.postgresql.org; Wed, 12 Aug 2020 00:01:37 +0000 Received: from ook.raf.org ([2402:1f00:8100:400::31]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5eCz-0002vH-Tu for pgsql-general@lists.postgresql.org; Wed, 12 Aug 2020 00:01:36 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id D0B675DE2E for ; Wed, 12 Aug 2020 10:01:28 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at ook.raf.org Received: from ook.raf.org ([127.0.0.1]) by localhost (ook.raf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uo4w1JYBuR5Y for ; Wed, 12 Aug 2020 10:01:26 +1000 (AEST) Received: by ook.raf.org (Postfix, from userid 1001) id 3AE865E319; Wed, 12 Aug 2020 10:01:26 +1000 (AEST) Date: Wed, 12 Aug 2020 10:01:26 +1000 From: raf To: pgsql-general@lists.postgresql.org Subject: Re: Implement a new data type Message-ID: <20200812000126.6ofbn4z7mrtee3ir@raf.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Aug 11, 2020 at 06:38:39AM -0700, Miles Elam 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