Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E514A1337B8D for ; Tue, 12 Oct 2010 01:09:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 71586-03 for ; Tue, 12 Oct 2010 04:09:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id C80BD1337B66 for ; Tue, 12 Oct 2010 01:09:08 -0300 (ADT) Received: (qmail invoked by alias); 12 Oct 2010 04:09:06 -0000 Received: from mue-88-130-47-091.dsl.tropolys.de (EHLO [192.168.0.113]) [88.130.47.91] by mail.gmx.net (mp004) with SMTP; 12 Oct 2010 06:09:06 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX18XHShnKRAXDcaX1aaMT9u84izu8Rxsb5LjYXUvT8 aSRWp2nT0rUHoh Message-ID: <4CB3DF63.6080909@gmx.net> Date: Tue, 12 Oct 2010 06:09:07 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Is there a conditional string-concatenation ? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/31 X-Sequence-Number: 34682 Hi, Is there a conditional string-concatenation ? I'd like to have an elegant way to connect 2 strings with some 3rd element between only if there really are 2 strings to connect. e.g. MyCat ( 'John', '_', 'Doe' ) --> 'John_Doe' while MyCat ( 'John', '_', '' ) --> 'John' MyCat ( '', '_', 'Doe' ) --> 'Doe' MyCat ( '', '_', '' ) --> NULL It should treat NULL and '' equally as empty and it should trim each of the 3 elements. so MyCat ( ' John ', '_', NULL ) --> 'John' MyCat ( 'John', NULL, 'Doe' ) --> 'JohnDoe'