Database Reference
In-Depth Information
SELECT "tag" FROM "hash_tags"
WHERE "prefix" = 'ca';
Just as we want, we'll get tags starting with the letters
ca
:
So far so good! Now, let's say the user has typed
cas
. In this case, we want to return all
the words starting with
cas
, but CQL doesn't have a starting-with operator. Instead, we'll
use a range slice query to describe the rows we're looking for. From the standpoint of lex-
ical string ordering, we're looking for strings that are lexically greater than
cas
, but lexic-
ally smaller than
cat
, since
t
is the next letter after
s
. Translated into a CQL query, it
looks like this:
SELECT "tag" FROM "hash_tags"
WHERE "prefix" = 'ca'
AND "remaining" >= 's'
AND "remaining" < 't';
The remaining range slice will cover strings like
ssete
,
sual
, and
ssandra
, because
those are all lexically greater than
s
and lexically smaller than
t
. So, we get just the res-
ults we're looking for:
Supposing the user typed a couple more letters, for a total entry of
cassa
, we'd narrow
the range further:
SELECT "tag" FROM "hash_tags"
WHERE "prefix" = 'ca'