Is there a conditional string-concatenation ?

From: Andreas <maps(dot)on(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Is there a conditional string-concatenation ?
Date: 2010-10-12 04:09:07
Message-ID: 4CB3DF63.6080909@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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'

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Joshua Tolley 2010-10-12 04:18:22 Re: Is there a conditional string-concatenation ?
Previous Message Markus Schatten 2010-10-12 00:22:05 Re: get attribute from XML