Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5FF931337B66 for ; Tue, 12 Oct 2010 01:18:39 -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 73525-03 for ; Tue, 12 Oct 2010 04:18:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gw0-f46.google.com (mail-gw0-f46.google.com [74.125.83.46]) by mail.postgresql.org (Postfix) with ESMTP id 4406C1337B5A for ; Tue, 12 Oct 2010 01:18:30 -0300 (ADT) Received: by gwj17 with SMTP id 17so1626598gwj.33 for ; Mon, 11 Oct 2010 21:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:cc :subject:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=SnfiRrZCuqmLnBw5nGXLlowMjBR0xkfEqyttCFs/uAo=; b=mO49Hnrl+Q/msQxT7hK1mXfZTzcP+jB5vyeRMZcl70Klu4pViZfqO2s1koeaS8zNtq PBxuKsGrIg0o5wid+OG1s2ghhbn5aK7btovGI/eL/U2PKeXK2kul3SdqtumT55KiXggl SWaTbEtE+sTJfIP6KFbxEaQv5LRo3DFtYnVdY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:cc:subject:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=rinXEGCNnA/2yDaRPMrJRsu/e1IOXA07YEIsrTRt4VFBcNy2WDZ+7Bp5HVRrCeNtwt vVVkD6/07AcY5PfUFs1DnCGtU2exTmjxW0iy/95NNO/pKNBlRaskCOh1TNJJHS6o2ZQU v+cEpokYXPb/h3I2vCtv1SCGYaE8+pTCy6VMU= Received: by 10.236.105.133 with SMTP id k5mr13517017yhg.20.1286857110123; Mon, 11 Oct 2010 21:18:30 -0700 (PDT) Received: from eddie (c-67-186-249-122.hsd1.ut.comcast.net [67.186.249.122]) by mx.google.com with ESMTPS id 70sm5862863yhl.28.2010.10.11.21.18.27 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 11 Oct 2010 21:18:28 -0700 (PDT) Message-ID: <4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com> Date: Mon, 11 Oct 2010 22:18:22 -0600 From: Joshua Tolley To: Andreas Cc: pgsql-sql@postgresql.org Subject: Re: Is there a conditional string-concatenation ? References: <4CB3DF63.6080909@gmx.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="H+4ONPRPur6+Ovig" Content-Disposition: inline In-Reply-To: <4CB3DF63.6080909@gmx.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201010/32 X-Sequence-Number: 34683 --H+4ONPRPur6+Ovig Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Oct 12, 2010 at 06:09:07AM +0200, Andreas wrote: > Hi, > Is there a conditional string-concatenation ? Perhaps this: CREATE OR REPLACE FUNCTION mycat(text, text, text) RETURNS TEXT LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN $1 IS NULL OR $1 = '' THEN trim($3) WHEN $3 IS NULL OR $3 = '' THEN trim($1) ELSE trim($1) || trim(coalesce($2, '')) || trim($3) END; -- Joshua Tolley / eggyknap End Point Corporation http://www.endpoint.com --H+4ONPRPur6+Ovig Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkyz4Y4ACgkQRiRfCGf1UMMfDQCff8A3r4rXAwvO//RV5XM/Jd2d VuEAnAkHuI9DAoyesUchv6195SVZKZ7l =HOzF -----END PGP SIGNATURE----- --H+4ONPRPur6+Ovig--