The LIKE
condition allows us to use wildcards in the where clause of an SQL statement. This allows us to perform pattern matching. The LIKE
condition can be used in any valid SQL statement - select, insert, update, or delete. Like this
SELECT * FROM users WHERE user_name like 'babu%';
like the same above operation any query is available for Cassandra in CLI.
CQL query language is a NoSQL interface that is intentionally similar to SQL, providing users who are comfortable with relational databases a familiar language that ultimately lowers the barrier of entry to Apache Cassandra.
Cassandra provides a database query language called CQL (Cassandra Query Language) that is similar to SQL, but does not support the full set of SQL features supported by most relational database systems. Listed below are examples for how to write select, insert, update, and delete statements.
Cassandra Query Language (CQL) is a query language for the Apache Cassandra database. The Cassandra Query Language (CQL) is the primary language for communicating with the Apache Cassandra™ database. The most basic way to interact with Apache Cassandra is using the CQL shell, cqlsh.
Since Cassandra 3.4 (3.5 recommended), LIKE queries can be achieved using a SSTable Attached Secondary Index (SASI).
For example:
CREATE TABLE cycling.cyclist_name ( id UUID PRIMARY KEY, lastname text, firstname text );
Creating the SASI as follows:
CREATE CUSTOM INDEX fn_prefix ON cyclist_name (firstname) USING 'org.apache.cassandra.index.sasi.SASIIndex';
Then a prefix LIKE query is working:
SELECT * FROM cyclist_name WHERE firstname LIKE 'M%'; SELECT * FROM cyclist_name WHERE firstname LIKE 'Mic%';
These examples and more configuration options, like suffix queries, can be found in the documentation
A more in depth explanation about how SASI works can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With