From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Matthias Teege <matthias(at)mteege(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: concat strings but spaces |
Date: | 2004-04-06 18:15:55 |
Message-ID: | 4072F3DB.6090104@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Matthias Teege wrote:
> I try to concat values from three fields in a function like this:
>
> create or replace function
> fconcat_name(varchar, varchar, varchar) returns varchar as '
> declare
> ttl alias for $1;
> vnm alias for $2;
> nme alias for $3;
> begin
> return ttl || '' '' || vnm || '' '' || nme;
> end;
> ' language plpgsql;
>
> That works but if one of the fields is empty there are to much
> spaces in the result. Is there any alternative to a monster
> if-then construct?
Maybe like this:
create or replace function
fconcat_name(varchar, varchar, varchar) returns varchar as '
select replace($1 || '' '' || $2 || '' '' || $3, '' '', '' '')
' language sql;
regression=# select fconcat_name('John','','Doe');
fconcat_name
--------------
John Doe
(1 row)
HTH,
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | William White | 2004-04-06 18:18:55 | Re: SQL trees and other nonsense... |
Previous Message | Tom Lane | 2004-04-06 18:07:33 | Re: Crash in postgres/linux on verly large database |