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 990349DCA7A for ; Fri, 24 Mar 2006 12:55:43 -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 77801-02 for ; Fri, 24 Mar 2006 12:55:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 2E80C9DCA03 for ; Fri, 24 Mar 2006 12:55:41 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 6FDA630920; Fri, 24 Mar 2006 17:55:40 +0100 (MET) From: August Zajonc X-Newsgroups: pgsql.hackers Subject: Re: [GENERAL] A real currency type Date: Fri, 24 Mar 2006 08:54:54 -0800 Organization: Hub.Org Networking Services Lines: 52 Message-ID: References: <200603211349.k2LDnIR15871@candle.pha.pa.us> <200603212130.52525.peter_e@gmx.net> <44206933.6050603@dunslane.net> <20060321222359.GI11045@svana.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <20060321222359.GI11045@svana.org> To: pgsql-hackers@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200603/1048 X-Sequence-Number: 81446 Martijn van Oosterhout wrote: > On Tue, Mar 21, 2006 at 03:59:31PM -0500, Andrew Dunstan wrote: >>> I think such types would be better implemented as some sort of >>> structured type, possibly with constructors and methods and all the >>> other stuff that SQL talks about. We don't have all of that yet -- >>> maybe we don't need all of it immediately -- but before we start >>> endorsing many of these types I'd like to see some consideration given >>> to this issue. >> Yeah, looks interesting but let's find the wrinkles. I was wondering if >> it might have relevance to what I wanted to do with enumeration types, >> i.e. we would tag each one with its particular enumeration id. > > I have considered making enumeration types with this. It would probably > work but kind of overkill. The main problem being that this code is > seriously aimed at creating new types that you intend to do operations > on, create operators for. An enumeration is just that, an enumeration. > >> I also don't like the idea of it being done with user tables - if this >> is core material then the tags should go in the catalog, ISTM. > > But the user is providing the list of tags when creating the type. > Unless you are proposing copying the tag table to the catalog when the > type is created? You can't store all the tags for all tagged types in > one tag table either. At least, that wasn't what I was envisiging. See > the currency type where the tag-table also stores the format string for > output. No other tagged type is going to need that information. > > SQL types with constructors and methods might provide this also, I > don't know. My purpose with this was allowing people to simply create > new types with specific behaviour without writing functions in C. Right > now type input/output functions cannot be written in anything other > than C. Here are a few C functions that handle these new types in a > generic way and user can write little pl/pgsql wrappers to customise > the output. > > Have a ncie day, > Martin, This would be extremely useful to have. For example, if I store currencies tagged properly, I could do a select and multiply the currency tag by the factor associated with that tag. This would allow easily quoting financials in a standard currency, but protect against type mismatches presumably at the database level (USD + AUD fails). Either way, it should be easy to add tags (ie, INSERT or similar) or get a list of them (SELECT * from somewhere where type = "currency"). I'm sure this later will be the case system catalog or not. - August