Doug Quale wrote: > "Marc G. Fournier" <scrappy@xxxxxxxxxxxxxx> writes: > >> On Wed, 19 Oct 2005, Richard_D_Levine@xxxxxxxxxxxx wrote: >> >>> I was referring to trailing blanks, but did not explicitly say it, >>> though showed it in the examples. I am pretty sure that the SQL >>> standard says that trailing whitespace is insignificant in string >>> comparison. >> >> Then we are broken too :) >> >> # select 'a ' = 'a '; >> ?column? >> ---------- >> f >> (1 row) > > # select 'a'::char(8) = 'a '::char(8); > ?column? > ---------- > t > (1 row) > > Trailing blanks aren't significant in fixed-length strings, so the > question is whether Postgresql treats comparison of varchars right. This result is being misinterpreted. select length('a'::char(8)) ==> 1 select length('a '::char(8)) ==> 1 So it isn't that the two different strings are comparing equal. The process of casting them to char(8) is trimming the blanks, so by the time they become fixed length strings, they are indeed equal. Addressing Dan's subsequent note here, I tried this in Oracle: select length(cast('a ' as varchar2(30))) from dual ==> 2 So Oracle does not trim when it casts. The subject of whether casting should trim trailing blanks is yet another tangential discussion. I would say that if the user hasn't specifically asked for a trim, it shouldn't happen, but I have not read the standard on this. We're all discussing these intricacies from a comp sci perspective. >From a normal user's perspective, of course, they would prefer the DBMS to hide these types of nuances. -- Guy Rouillier ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster