Search Postgresql Archives

Re: How to define + operator for strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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    === 


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux