0

For example. I have a map under the column 'users' in a table called 'table' with primary key 'Id'.

If the map looks like this, {{'Phone': '1234567899'}, {'City': 'Dublin'}}, I want to get the value from key 'Phone' for specific 'Id', in Cassandra database.

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
  • Welcome to SO! Please see "[ask]" and the linked pages and "[MCVE]". We appreciate that you might be new, but we do expect evidence of the effort you've put into this. Where did you search? Why didn't it help? If it did, where is the code you wrote to test what you learned? If you didn't write code, why not? What is the minimal code that demonstrates the problem you encountered, along with the explanation of the problem, and the minimal input data and the expected result? Without that, it's hard to help you, and it looks like you want us to write code for you. – the Tin Man Feb 10 '22 at 06:49

1 Answers1

0

Yes, that's possible to do with CQL when using a MAP collection.

To test this, I created a simple table using the specifications and data you mentioned above:

> CREATE TABLE stackoverflow.usermap (
  id text PRIMARY KEY,
  users map<text, text>);

> INSERT INTO usermap (id,users)
  VALUES ('1a',{'Phone': '1234567899','City': 'Dublin'});

> SELECT * FROM usermap WHERE id='1a';

 id | users
----+-------------------------------------------
 1a | {'City': 'Dublin', 'Phone': '1234567899'}

(1 rows)

Then, I queried with the same WHERE clause, but altering my SELECT to pull back the user's phone only:

> SELECT users['Phone'] FROM usermap WHERE id='1a';

 users['Phone']
----------------
     1234567899

(1 rows)
Aaron
  • 55,518
  • 11
  • 116
  • 132