From: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to define + operator for strings |
Date: | 2006-04-28 10:27:40 |
Message-ID: | 20060428102740.GC8542@webserv.wug-glas.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
am 28.04.2006, um 12:59:25 +0300 mailte Andrus folgendes:
> I want to create portable code which runs in other dbms without
> modification.
>
> Unfortunately this other dbms uses + for string concatenation and has no way
> to define operators.
>
> How to define + operator as alias of || operator for strings so I can use
>
> SELECT firstname+ ' '+ lastname
create function _string_plus(text, text) returns text as $$
begin
return $1 || $2;
end;
$$ language plpgsql;
create operator + (
leftarg = text,
rightarg = text,
procedure = _string_plus,
commutator = +
);
test=*# select 'foo' + 'bar';
?column?
----------
foobar
(1 row)
Please read http://www.postgresql.org/docs/8.1/interactive/xoper.html
HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47215, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===
From | Date | Subject | |
---|---|---|---|
Next Message | Alban Hertroys | 2006-04-28 11:52:09 | A few things on intervals |
Previous Message | Andrus | 2006-04-28 09:59:25 | How to define + operator for strings |