Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 2CA5F633474 for ; Wed, 23 Dec 2009 04:34:43 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70690-06 for ; Wed, 23 Dec 2009 08:34:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outA.internet-mail-service.net (outa.internet-mail-service.net [216.240.47.224]) by mail.postgresql.org (Postfix) with ESMTP id 22DE4633419 for ; Wed, 23 Dec 2009 04:34:36 -0400 (AST) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id 0E26CC8B2E for ; Wed, 23 Dec 2009 00:34:34 -0800 (PST) X-Client-Authorized: MaGic Cook1e Received: from [192.168.2.113] (adsl-71-135-173-32.dsl.pltn13.pacbell.net [71.135.173.32]) by idiom.com (Postfix) with ESMTP id CF2E22D6013 for ; Wed, 23 Dec 2009 00:34:33 -0800 (PST) Message-ID: <4B31D619.1090706@obviously.com> Date: Wed, 23 Dec 2009 00:34:33 -0800 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.23) Gecko/20090410 SUSE/1.1.18-0.1 SeaMonkey/1.1.18 MIME-Version: 1.0 To: sql pgsql Subject: Using || operator to fold multiple columns into one Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/69 X-Sequence-Number: 33507 Dear experts, This point is confusing me with the || operator. I've got a table with "one column per data type", like so: # \d context_keyvals; Table "public.context_keyvals" Column | Type | Modifiers -------------+-----------------------------+----------- context_key | integer | not null keyname | text | t_number | integer | t_string | text | t_boolean | boolean | t_date | timestamp without time zone | Indexes: "context_keyvals_ck" btree (context_key) CLUSTER Foreign-key constraints: "context_keyvals_context_key_fkey" FOREIGN KEY (context_key) REFERENCES contexts(context_key) ON DELETE CASCADE # select version() PostgreSQL 8.3.8 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2 ------------------------------ Just for pretty sake I'd like to be able to use psql to view it like this: # select context_key,keyname,t_number||t_string||t_date||t_boolean as value from context_keyvals; But it is not working, the columns always come up empty. I can use the || operator to concatenate strings: # select '--'||t_number::text from context_keyvals; But the moment I try to combine columns, the result is blank. # select '--'||t_number::text||t_string::text from context_keyvals; What's up?