0

I have table with varchar(15) column Code, which is also primary key. In one of the rows, value of this column is "K553". When I do select with WHERE Code='K553 ' this row is selected even when no spaces are in that string! Also when I try to add new row with value "K553 " I get error which says that primary key already exists. If I add some spaces to start of string, not end of string then it works as expected. What is this behavior?!

Thilo
  • 257,207
  • 101
  • 511
  • 656
Ondřej
  • 1,645
  • 1
  • 18
  • 29
  • 2
    This is standard behaviour for a varchar type – GuidoG Nov 09 '16 at 11:55
  • If you really need codes with significant trailing whitespace, this is very unfortunate for you. But do you? – Thilo Nov 09 '16 at 11:58
  • Why this behavoir? Because it makes sense! – jarlh Nov 09 '16 at 11:58
  • @jarlh You insert something and select it by criteria that does not correspond to inserted data. This makes sense to you??? – Ondřej Nov 09 '16 at 12:04
  • Hey, this sentence has a trailing space at the end . Can you read it? (Character types are more or less for human langauge. You can even have case insensitive primary keys, and get k553 returned.) – jarlh Nov 09 '16 at 12:05
  • Is there any way to turn of this crap and select only data, that are corresponding with where clause? This works in Oracle database by default. – Ondřej Nov 09 '16 at 12:07

0 Answers0