Re: How to define + operator for strings

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to define + operator for strings
Date: 2006-04-28 15:19:20
Message-ID: 1134.1146237560@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-04-28 15:28:41 Re: Alternative for vacuuming queue-like tables
Previous Message linux 2006-04-28 14:53:25 Init script for 8.1 compiled on Debian Stable