Re: How to define + operator for strings

Поиск
Список
Период
Сортировка
От A. Kretschmer
Тема Re: How to define + operator for strings
Дата
Msg-id 20060428102740.GC8542@webserv.wug-glas.de
обсуждение исходный текст
Ответ на How to define + operator for strings  ("Andrus" <eetasoft@online.ee>)
Ответы Re: How to define + operator for strings  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: "Andrus"
Дата:
Сообщение: How to define + operator for strings
Следующее
От: Alban Hertroys
Дата:
Сообщение: A few things on intervals