Re: Is there a conditional string-concatenation ?

From: Joshua Tolley <eggyknap(at)gmail(dot)com>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Is there a conditional string-concatenation ?
Date: 2010-10-12 04:18:22
Message-ID: 4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Osvaldo Kussama 2010-10-12 05:03:41 Re: Is there a conditional string-concatenation ?
Previous Message Andreas 2010-10-12 04:09:07 Is there a conditional string-concatenation ?