Bhanu Boppana
Bhanu Boppana

Reputation: 134

Cassandra : Using output of one query as input to another query

I have two tables one is users and other is expired_users.

users columns-> id, name, age expired_users columns -> id, name

I want to execute the following query.

delete from users where id in (select id from expired_users);

This query works fine with SQL related databases. I want find a solution to solve this in cassandra.

PS: I don't want to add any extra columns in the tables.

Upvotes: 1

Views: 729

Answers (2)

nevsv
nevsv

Reputation: 2466

What you want to is to use join as a filter for your delete statement, and this is not what the Cassandra model is built for.

AFAIK there is no way to perform this using cql. If you want to perform this action without changing the schema - run external script in any language that has drivers for Cassandra.

Upvotes: 1

Gunwant
Gunwant

Reputation: 979

While designing cassandra data model, we cannot think exactly like RDBMS . Design like this --

create table users (
id int,
name text,
age int,
expired boolean static,
primary key (id,name)
);

To mark a user as expired -- Just insert the same row again

insert into users (id,name,age,expired) values (100,'xyz',80,true);

you don't have to update or delete the row, just insert it again, previous column values will get overridden.

Upvotes: 2

Related Questions