Python Data Persistence – Querying Cassandra Table
Predictably. CQL also lias the SELECT statement to fetch data from a Cassandra table. The easiest usage is employing to fetch data from all columns in a table.
cq1sh:mykeyspace> select * from products; productid | name | price ------------+-------------+--------- 5 | ’Printer' | 9000 1 | 'Laptop' | 25000 2 | 'TV' | 40000 4 | 'Scanner' | 5000 6 | 'Mobile' | 15000 3 | 'Router' | 2000 (6 rows)
All conventional logical operators are allowed in the filter criteria specified with the WHERE clause. The following statement returns product names with prices greater than 10000.
cq1sh:mykeyspace> select * from products where price>10000 allow filtering; productid | name | price ------------+-------------+--------- 1 | 'Laptop' | 25000 2 | 'TV' | 40000 6 | 'Mobile' | 15000 (3 rows
- Python Data Persistence – ORM – Filter Criteria
- Python Data Persistence – ORM – Querying
- Python Data Persistence – ORM – Update Data
Use of ALLOW FILTERING is necessary here. By default, CQL only allows select queries where all records read will be returned in the result set. Such queries have predictable performance. The ALLOW FILTERING option allows to explicitly allow (some) queries that require filtering. If the filter criteria consist of partition key columns only = and IN operators are allowed.
UPDATE and DELETE statements of CQL are used as in SQL. However, both must have filter criteria based on the primary key. (Note the use of’—’ as a commenting symbol)
cq1sh:mykeyspace> - -update syntax cq1sh:mykeyspace> update new products set price=45000 where productID=2; cq1sh:mykeyspace> --delete syntax cq1sh:mykeyspace> delete from new products where productID=6;