Re: How to define + operator for strings

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to define + operator for strings
Дата
Msg-id 1134.1146237560@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How to define + operator for strings  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-general
"A. Kretschmer" <andreas.kretschmer@schollglas.com> writes:
> am  28.04.2006, um 12:59:25 +0300 mailte Andrus folgendes:
>> How to define + operator as alias of || operator for strings

> 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 = +
> );

There's no need to bother with creating a function, just make the +
operator point at the same underlying function that || already uses
("textcat" I believe).

However, the reply is really incomplete without pointing out why this is
not such a hot idea: text + text will tend to capture ambiguous cases,
and thus possibly break queries that used to work (date + integer is a
case that comes to mind as being at risk).

Refusing to deal with databases that can't handle the 14-year-old SQL
standard spelling of concatenation would be a better plan IMHO --- if
they can't get this right, it's unlikely that they are much better on
a lot of other points that will be harder to work around.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Volker Aßmann
Дата:
Сообщение: Postmaster process on port 10000
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Alternative for vacuuming queue-like tables