user3310334
user3310334

Reputation:

Updating to empty set

I just created a new column for my table

alter table user add (questions set<timeuuid>);

Now the table looks like

user (
    google_id text PRIMARY KEY,
    date_of_birth timestamp,
    display_name text,
    joined timestamp,
    last_seen timestamp,
    points int,
    questions set<timeuuid>
)

Then I tried to update all those null values to empty sets, by doing

update user set questions = {} where google_id = ?;

for each google id.

However they are still null.

How can I fill that column with empty sets?

Upvotes: 1

Views: 1464

Answers (2)

user3310334
user3310334

Reputation:

I've learnt that there's not really such a thing as an empty set, or list, etc.

These display as null in cqlsh.

However, you can still add elements to them, e.g.

> select * from id_set;
 set_id                | set_content
-----------------------+---------------------------------
 104649882895086167215 | null
 105781005288147046623 | null

> update id_set set set_content = set_content + {'apple','orange'} where set_id = '105781005288147046623';
 set_id                | set_content
-----------------------+---------------------------------
 104649882895086167215 | null
 105781005288147046623 | { 'apple', 'orange' }

So even though it displays as null you can think of it as already containing the empty set.

Upvotes: 1

Horia
Horia

Reputation: 2982

A set, list, or map needs to have at least one element because an empty set, list, or map is stored as a null set.

source

Also, this might be helpful if you're using a client (java for instance).

Upvotes: 1

Related Questions