Re: How to define + operator for strings - Mailing list pgsql-general

From Tom Lane
Subject Re: How to define + operator for strings
Date
Msg-id 1134.1146237560@sss.pgh.pa.us
Whole thread Raw
In response to Re: How to define + operator for strings  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List 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 by date:

Previous
From: Volker Aßmann
Date:
Subject: Postmaster process on port 10000
Next
From: Tom Lane
Date:
Subject: Re: Alternative for vacuuming queue-like tables