Re: Is there a conditional string-concatenation ? - Mailing list pgsql-sql

From Joshua Tolley
Subject Re: Is there a conditional string-concatenation ?
Date
Msg-id 4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com
Whole thread Raw
In response to Is there a conditional string-concatenation ?  (Andreas <maps.on@gmx.net>)
List 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

pgsql-sql by date:

Previous
From: Andreas
Date:
Subject: Is there a conditional string-concatenation ?
Next
From: Osvaldo Kussama
Date:
Subject: Re: Is there a conditional string-concatenation ?