Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 07CF36355E0 for ; Thu, 24 Dec 2009 05:56:04 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 58003-07 for ; Thu, 24 Dec 2009 09:55:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 9D0796355DE for ; Wed, 23 Dec 2009 23:08:13 -0400 (AST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id DB94F1E0441; Thu, 24 Dec 2009 11:08:09 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id bPMnX3H+c4Fk; Thu, 24 Dec 2009 11:08:08 +0800 (WST) Received: from [10.1.1.6] (124-169-133-89.dyn.iinet.net.au [124.169.133.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id EEDA61E0440; Thu, 24 Dec 2009 11:08:07 +0800 (WST) Message-ID: <4B32DB14.6080308@postnewspapers.com.au> Date: Thu, 24 Dec 2009 11:08:04 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: Rosser Schwarz CC: Bryce Nesbitt , sql pgsql Subject: Re: Using || operator to fold multiple columns into one References: <4B31D619.1090706@obviously.com> <4B31D86D.9030000@postnewspapers.com.au> <37d451f70912231304i3515e575x69b31638962739a6@mail.gmail.com> In-Reply-To: <37d451f70912231304i3515e575x69b31638962739a6@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.338 tagged_above=-10 required=5 tests=AWL=0.261, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/83 X-Sequence-Number: 33521 On 24/12/2009 5:04 AM, Rosser Schwarz wrote: > On Wed, Dec 23, 2009 at 1:44 AM, Craig Ringer > wrote: > >> SELECT COALESCE( t_number::text, t:string::text, t_date::text, t_boolean::text) AS value; > > Your invocation of COALESCE is incorrect -- it is n-ary, but it > returns its first non-NULL argument. Yes. That was the point. I think we're assuming the OP wants different things. You're assuming they're trying to concatenate all fields, where more than one field in a given record may be non-null. I'm assuming that all but one field in each record will be null, and they want to show the "value" of the record - in other words, they're using the record as a sort of union type. It looks like that from the example they gave. -- Craig Ringer