X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B46409DD56C for ; Tue, 21 Mar 2006 10:27:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83723-06 for ; Tue, 21 Mar 2006 10:27:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 24C909DD566 for ; Tue, 21 Mar 2006 10:27:07 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1FLhpG-0003H4-AS; Wed, 22 Mar 2006 01:27:10 +1100 Date: Tue, 21 Mar 2006 15:27:10 +0100 From: Martijn van Oosterhout To: Bruce Momjian Cc: PostgreSQL-development Subject: Re: [GENERAL] A real currency type Message-ID: <20060321142710.GD11045@svana.org> Reply-To: Martijn van Oosterhout References: <20050828170727.GC12498@svana.org> <200603211349.k2LDnIR15871@candle.pha.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZJcv+A0YCCLh2VIg" Content-Disposition: inline In-Reply-To: <200603211349.k2LDnIR15871@candle.pha.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.124 required=5 tests=[AWL=0.124] X-Spam-Score: 0.124 X-Spam-Level: X-Archive-Number: 200603/867 X-Sequence-Number: 81265 --ZJcv+A0YCCLh2VIg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 21, 2006 at 08:49:18AM -0500, Bruce Momjian wrote: >=20 > This looks very interesting. Should we add it to the core distribution? Excellent question. As yet I have received very little feedback on it, though it does work as advertised. I have had some people complain that while they'd like to use it (especially the timestamp-that-remembers- the-timezone), they don't like the idea of an external module. I suppose the are a few technical issues that could be raised, like the fact that it searches user tables during the parse phase, but this is a generic problem with non-immutable type input functions. I'd like it to be considered for inclusion. If the interest is there I can make any changes people suggest. Have a nice day, >=20 > -------------------------------------------------------------------------= -- >=20 > Martijn van Oosterhout wrote: > -- Start of PGP signed section. > > For a while I've been wondering about making a type that was really a > > shell around a base type that tagged the type in some way. For example, > > associating a currency with a numeric and complaining about additions > > between mismatches. > >=20 > > Well, I did it and it's available here: > > http://svana.org/kleptog/pgsql/taggedtypes.html > >=20 > > Below some examples of it in action. Yes, that's a timestamp that > > remembers the timezone. Neat huh? > >=20 > > Tested on 7.4 and a recent 8.1devel so it should work for most people. > > Installation reports welcome. Note, this is beta software, don't run it > > on your production server. Thanks. > >=20 > > Have a nice day, > >=20 > >=20 > > test=3D# select '5.6 USD'::currency + '4.5 USD'::currency;; > > ?column? =20 > > ----------- > > 10.10 USD > > (1 row) > >=20 > > test=3D# select '5.6 USD'::currency + '4.5 AUD'::currency;; > > ERROR: Using operator +(currency,currency) with incompatable tags (USD= ,AUD) > > test=3D# select c1, print_currency(c1) from c; > > c1 | print_currency=20 > > ------------+---------------- > > 232.44 USD | US$ 232.44 > > 21.20 EUR | ? 21.20 > > -13.44 AUD | AU$ -13.44 > > 0.01 USD | US$ 0.01 > > 14.00 AUD | AU$ 14.00 > > (5 rows) > >=20 > > test=3D# select 5.4*c1 from c where tag(c1) =3D 'AUD'; > > ?column? =20 > > ------------ > > -72.58 AUD > > 75.60 AUD > > (2 rows) > >=20 > > test=3D# select t, "timestamp"(t), date_part('hour',t) from c; > > t | timestamp | date_p= art=20 > > -----------------------------------------+---------------------+-------= ---- > > 2005-08-14 02:00:00+02 Europe/Amsterdam | 2005-08-14 02:00:00 | = 2 > > 2005-08-14 02:00:00+02 Australia/Sydney | 2005-08-14 10:00:00 | = 10 > > 2005-08-14 02:00:00+02 Asia/Hong_Kong | 2005-08-14 08:00:00 | = 8 > > 2005-08-14 02:00:00+02 America/New_York | 2005-08-13 20:00:00 | = 20 > > 2005-08-14 02:00:00+02 Asia/Kuwait | 2005-08-14 03:00:00 | = 3 > > (5 rows) > >=20 > > --=20 > > Martijn van Oosterhout http://svana.org/kleptog/ > > > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is= a > > > tool for doing 5% of the work and then sitting around waiting for som= eone > > > else to do the other 95% so you can sue them. > -- End of PGP section, PGP failed! >=20 > --=20 > Bruce Momjian http://candle.pha.pa.us > SRA OSS, Inc. http://www.sraoss.com >=20 > + If your life is a hard drive, Christ can be your backup. + >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings --=20 Martijn van Oosterhout http://svana.org/kleptog/ > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a > tool for doing 5% of the work and then sitting around waiting for someone > else to do the other 95% so you can sue them. --ZJcv+A0YCCLh2VIg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFEIA0+IB7bNG8LQkwRArqvAJ9w4qOV2JAwAzq0PW86OU1FoNdScQCfa08A w3Pz3MDRMBGdrs0ObXg+AeI= =do1B -----END PGP SIGNATURE----- --ZJcv+A0YCCLh2VIg--