Re: CHAR(n) always trims trailing spaces in 7.4

From: elein <elein(at)varlena(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: elein <elein(at)varlena(dot)com>, "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>, "news(dot)postgresql(dot)org" <jlim(at)natsoft(dot)com(dot)my>, pgsql-sql(at)postgresql(dot)org
Subject: Re: CHAR(n) always trims trailing spaces in 7.4
Date: 2004-02-19 18:55:05
Message-ID: 20040219105505.S25537@cookie.varlena.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

I guess I am asking about the cast sequence from
char(n) to text.
(' '::char(n))::text trims spaces. This is wrong, imo.
' '::text does not trim spaces.
' '::char(n) does not trim spaces and pads.

char(n) should not trim spaces, right? And
it doesn't on an insert. Text does not trim spaces.
Somewhere the space trimming occurs.

If it is in the operator || then the operator is wrong.
If char(n) is properly defined to not trim spaces then
there should be a separate cat for char(n). It is correct
for it to behave differently than cat for text and varchar
because of the different trimming behaviour.

I can do this patch if there is agreement. But
I may not be able to do it immediately.

elein

On Wed, Feb 18, 2004 at 11:58:37PM -0500, Tom Lane wrote:
> elein <elein(at)varlena(dot)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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2004-02-19 19:08:39 Re: Advice regarding configuration parameters
Previous Message Andrew Sullivan 2004-02-19 17:21:20 Re: Replication eRServer problems

Browse pgsql-sql by date

  From Date Subject
Next Message Joe Conway 2004-02-19 18:58:24 Re: crosstabs
Previous Message Jeremy Smith 2004-02-19 18:10:30 DISTINCT ON troubles