Re: How to define + operator for strings - Mailing list pgsql-general

From A. Kretschmer
Subject Re: How to define + operator for strings
Date
Msg-id 20060428102740.GC8542@webserv.wug-glas.de
Whole thread Raw
In response to How to define + operator for strings  ("Andrus" <eetasoft@online.ee>)
Responses Re: How to define + operator for strings  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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    ===

pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: How to define + operator for strings
Next
From: Alban Hertroys
Date:
Subject: A few things on intervals