Subject Re: [firebird-support] Issues in string indexing
Author Helen Borrie
At 04:45 PM 15/02/2006, you wrote:
>Hi,
>
>I am storing strings in the database table and indexing them. (all
>of them are less than 252 characters). Now if have the following
>string already in the table
>"abc"
>and i try to insert another string "abc " which is differnt than
>what is there in the database, it does not allow me to put that in the
>database.

Correct. You have defined this column as varchar. Trailing white
space characters are ignored when varchars are stored. To store
'abc' and 'abc ' and have them treated as distinct, the column would
have to be char. (But what a crazy idea!)


>When i equate the two string "abc" = "abc " that also matches. So is
>it a bug or it is designed like this.

It's designed like that, as per the SQL standard. Trailing white
space characters are ignored for equivalence tests.


>If I have strings like that and i want to insert it into the
>databsae how do i solve this problem.

Well, define the fields as char to *store* the trailing white space
characters (making 'abc', 'abc ' and 'abc ' three distinct values)
but nothing is going to help you to get past the equivalence test
rules. It is just not at all a bright idea to allow trailing white
space to be meaningful.


>If I use LIKE then it works fine but the trade off will be i don't
>have to use indexing then which will be big loss i suppose.

You could use STARTING WITH if you must do this thing. The optimizer
will use the index with this predicate if it considers it useful. Of
course, once you get to storing random numbers of whitespace
characters in your char columns, it won't be easy to work out which is which.

./heLen