0

My filter string during a Table Query looks like below...

string FilterString = string.Format("PartitionKey eq '{0}' 
and RowKey ge '{1}' and RowKey le '{2}'", 
partitionKey, startsWith, startsWith);

https://msdn.microsoft.com/library/azure/dd894031.aspx says you can do prefix matching for names. Lets say there are 3 names...

  • batman
  • superman
  • spiderman

I would like the query to return both superman and spiderman when I set the startsWith to 's'

The query above works when I say

RowKey ge 's' and Rowkey le 't'

However, I would like this to work when it says...

RowKey ge 's' and Rowkey le 's'

le is being treated as lt and IMHO it shouldn't have behaved the way it does. Am I doing something wrong?

1 Answer 1

1

If you want to get back superman and spiderman (not sure how DC & Marvel Comics would agree to that but that's another story :)), the query you want to issue is:

RowKey ge 's' and Rowkey lt 't'

Now let's consider this query:

RowKey ge 's' and Rowkey le 's'

Basically this query will only return data where RowKey eq s. To take an example, consider superman. Now superman is definitely greater than s so your first expression (RowKey ge 's') is true but at the same time your second expression (Rowkey le 's') is false so the entire expression's result will be false.

UPDATE

To test strings, you could simply write a console application like the following:

        string a = "s";
        string b = "superman";
        string c = "sz";
        Console.WriteLine(b.CompareTo(a));//Prints 1
        Console.WriteLine(b.CompareTo(c));//Prints -1

As you can see from above, superman is greater than s and is lesser than sz.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for helping out. My question is... why is Rowkey le 's' false? I can understand why Rowkey lt 's' is false. What is the difference between le & lt then??
le is less than or equal to and lt is less than. So "superman" <= "s" is certainly false. HTH.
Sorry, I don't agree. < is false for obvious reasons... but it is equal to s and that's why it should have worked. I can easily code around it, but the reason I asked the question is to understand if this is a bug, or I am missing something.
Agree with Gaurav, "superman" is greater than "s" during string comparison.
Is there a documentation that supports this behaviour?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.