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)
Список
Дерево обсуждения
Re: How to define + operator for strings "Andrus" <eetasoft@online.ee>
Re: How to define + operator for strings Martijn van Oosterhout <kleptog@svana.org>
Re: How to define + operator for strings Geoffrey <esoteric@3times25.net>
"A. Kretschmer" 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 по дате отправления