Search Postgresql Archives

Re: How to define + operator for strings

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

 



"A. Kretschmer" <andreas.kretschmer@xxxxxxxxxxxxxx> 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


[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