Re: CHAR(n) always trims trailing spaces in 7.4 - Mailing list pgsql-sql

From Tom Lane
Subject Re: CHAR(n) always trims trailing spaces in 7.4
Date
Msg-id 28866.1077166717@sss.pgh.pa.us
Whole thread Raw
In response to Re: CHAR(n) always trims trailing spaces in 7.4  (elein <elein@varlena.com>)
Responses Re: CHAR(n) always trims trailing spaces in 7.4  (elein <elein@varlena.com>)
List pgsql-sql
elein <elein@varlena.com> writes:
> So exactly what is the order of casts that produces
> different results with:

>     'x' || ' ' || 'x' and 'x' || ' '::char15 || 'x'

> Are operators being invoked both (text,text)?

The only relevant operator is "text || text" (there are also some ||
operators for arrays, bytea, and BIT, but these will all be discarded
as not the most plausible match).  Therefore, in your first example the
unspecified literals will all be presumed to be text, so the space does
not get trimmed.

One of the things we could think about as a way to tweak the behavior is
creating "||" variants that are declared to accept char(n) on one or
both sides.  These could actually use the same C implementation function
(textcat) of course.  But declaring them that way would suppress the
invocation of rtrim() as char-to-text conversion.

However, if we did that then "||" would behave differently from other
operators on character strings, so it doesn't seem like a very
attractive option to me.
        regards, tom lane


pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Distributed Transactions
Next
From: "Rodrigo Sakai"
Date:
Subject: Compiling pl/pgsql functions