Prerequisite – Cassandra
In this article, we will discuss the static column using the BATCH statement and how it works with the BATCH statement. Static column can be used for conditional update using a batch statement. Let’s have a look.
Let’s consider bank_emp_details is a table name and Id, Name, Bank_name, E_start_date and E_end_date are the fields where Id is a primary key and Name is a clustering key.
CREATE TABLE bank_emp_details( Id int, Name text, Bank_name text static, E_start_date date static, E_end_date date, primary key(Id, Name) );
Now, here we are using the Batch statement to update the static column. let’s have a look.
BEGIN BATCH INSERT INTO bank_emp_details(Id, Name, E_start_date, E_end_date) values (201, 'Ashish', '2019-12-06', '2020-12-06'); UPDATE bank_emp_details SET Bank_name = 'ABC' where Id = 201 IF Bank_name = NULL; APPLY BATCH;
Let’s see the output of inserted data and updated static column.
SELECT * from bank_emp_details;
Now, here we are trying to update a static column with conditional batch but it will give an error message “Batch with conditions can not span multiple partitions”.let’s have a look.
BEGIN BATCH INSERT INTO bank_emp_details(Id, Name, E_start_date, E_end_date) values (202, 'Ashish', '2019-12-06', '2022-12-06'); UPDATE bank_emp_details SET Bank_name = 'XYZ' where Id = 201 IF Bank_name = 'ABC'; APPLY BATCH;
The above query will return the following error message given below.
Now, here we will update the static column value with conditional batch which will work fine. let’s have a look.
BEGIN BATCH UPDATE bank_emp_details SET Bank_name = 'XYZ' where Id = 201 IF Bank_name = 'ABC'; APPLY BATCH;
The above query will return the following output given below.
Let’s see the final Output of the conditional batch using static column. Let’s have a look.
SELECT * from bank_emp_details;
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Static type in Cassandra
- Batch statement in Cassandra
- Overview of User Defined Type (UDT) in Cassandra
- Collection Data Type in Apache Cassandra
- Pre-defined data type in Apache Cassandra
- Tuple Type in Cassandra
- Altering a table to add a collection data type in Cassandra
- Updating MAP collection data type in Cassandra
- Counter Type in Cassandra
- Role of keys in Cassandra
- High Availability Mechanism in Cassandra
- Apache Cassandra tools
- Blob conversion function in Cassandra
- Designing models in Cassandra
- Introduction to Apache Cassandra
- Apache Cassandra (NOSQL database)
- Architecture of Apache Cassandra
- Overview of Data modeling in Apache Cassandra
- Concept of indexing in Apache Cassandra
- Monitoring cluster in Cassandra
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.