On 2018-03-20 15:34, Alexander Tabakov [email protected] 
[firebird-support] wrote:
> Hi All,
> 
> I have found strange behaviour concerning trailing spaces - following
> strings are equal:
> 
> 'ABC   ' = 'ABC'
> 
> You can try the following query:
> 
> _select_
> _  case when 'ABC   ' = 'ABC' then 1 else 0 end,_
> _  case when cast('ABC   ' as varchar(10)) = cast('ABC' as
> varchar(10)) then 1 else 0 end,_
> _  char_length('ABC   '),_
> _  char_length('ABC')_
> _from_
> _  rdb$database_
> 
> This query was tested on FB v.1.5.6, 2.5.8 & 3.0.3 - while char length
> (or strlen on 1.5) is different, the strings are always equal.
> 
> Is this by design :)

Yes it is. The SQL standard specifies that when comparing strings 
(char/varchar), the shorter value is right padded with blanks to the 
length of the longer value before comparison (or at least: behave as if 
the shorter value is blank-padded). Blanks are either spaces (0x20) for 
'normal' strings or NUL (0x00) for binary strings.

Mark

Reply via email to