pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joshua Tolley <eggyknap@gmail.com>
To: Andreas <maps.on@gmx.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Is there a conditional string-concatenation ?
Date: Mon, 11 Oct 2010 22:18:22 -0600
Message-ID: <4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com> (raw)
In-Reply-To: <4CB3DF63.6080909@gmx.net>
References: <4CB3DF63.6080909@gmx.net>

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

Attachments:

  [application/pgp-signature] signature.asc (196B, ../4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com/2-signature.asc)
  download

view thread (4+ messages)  latest in thread

Message-ID: <4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com>
Permalink:  ../4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com/
Also on:    postgresql.org/message-id/4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: eggyknap@gmail.com, maps.on@gmx.net
  Subject: Re: Is there a conditional string-concatenation ?
  In-Reply-To: <4cb3e194.ea05ec0a.3e4b.06b2@mx.google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox