char(n) to varchar or text conversion should strip trailing spaces - Mailing list pgsql-hackers

From Tom Lane
Subject char(n) to varchar or text conversion should strip trailing spaces
Date
Msg-id 2468.1037400879@sss.pgh.pa.us
Whole thread Raw
List pgsql-hackers
I've gotten really tired of explaining to newbies why stuff involving
char(n) fields doesn't work like they expect.  Our current behavior is
not valid per SQL92 anyway, I believe.

I think there is a pretty simple solution now that we have pg_cast:
we could stop treating char(n) as binary-equivalent to varchar/text,
and instead define it as requiring a runtime conversion (which would
be essentially the rtrim() function).  The cast in the other direction
would be assignment-only, so that any expression that involves mixed
char(n) and varchar/text operations would be evaluated in varchar
rules after stripping char's insignificant trailing blanks.

If we did this, then operations like    WHERE UPPER(charcolumn) = 'FOO'
would work as a newbie expects.  I believe that we'd come a lot closer
to spec compliance on the behavior of char(n), too.

Comments?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: RI_FKey_check: foreign key constraint blocks parallel
Next
From: Tom Lane
Date:
Subject: Re: Transaction safe Truncate