X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BB2BD5E4719 for ; Wed, 1 Sep 2004 11:20:22 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84222-08 for ; Wed, 1 Sep 2004 14:20:15 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5A7C55E3632 for ; Wed, 1 Sep 2004 11:20:13 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i81EJsX1006205; Wed, 1 Sep 2004 10:19:57 -0400 (EDT) To: Peter Eisentraut Cc: sad , Michael Glaesemann , Stephan Szabo , pgsql-sql@postgresql.org Subject: Re: casting BOOL to somthng In-reply-to: <200409010859.08037.peter_e@gmx.net> References: <200408311306.25545.sad@bankir.ru> <8AF2CE57-FBE1-11D8-A2A0-000A95C88220@myrealbox.com> <200409010955.45834.sad@bankir.ru> <200409010859.08037.peter_e@gmx.net> Comments: In-reply-to Peter Eisentraut message dated "Wed, 01 Sep 2004 08:59:08 +0200" Date: Wed, 01 Sep 2004 10:19:54 -0400 Message-ID: <6204.1094048394@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/15 X-Sequence-Number: 18861 Peter Eisentraut writes: > The cast to text, however, is part of the data model, and it has to be > both natural and universal. I think you agree that there is no > universal, obvious correspondence between character strings and boolean > values, at least not nearly as universal and obvious as the well-known > correspondence between character strings and numbers. We could pick > one arbitrary correspondence and implement it, and if we did we would > probably pick one that is consistent with the mapping used by libpq and > other frontends. But doing that gains no functionality, so why bother? Actually it does gain functionality, because there are plenty of times when you need to manipulate a textual representation of a data value. We have casts to text for many datatypes already: castsource | castcontext -----------------------------+------------- character | i character varying | i "char" | i name | i bigint | i smallint | i integer | i oid | i real | i double precision | i macaddr | e cidr | e inet | e date | i time without time zone | i timestamp without time zone | i timestamp with time zone | i interval | i time with time zone | i numeric | i (20 rows) and I think it is reasonable to say that we should have them for all types. My only beef with the above table is that most of these casts should not be implicitly invokable --- I think you should have to write an explicit CAST. As for the "which representation" argument, both consistency and implementation simplicity say that it should be whatever the datatype's output function delivers. Indeed it's just a historical accident that Postgres didn't define the datatype output functions as returning "text" values in the first place. regards, tom lane