I am trying to add a primary key using pycassa. I can do that using CQL3 but I cannot find any document that explains how to do this with Pycassa in the web. I googled too much, didnt find anything.
Does anyone know how can I specify which will be my primary key of my column family using Pycassa?
Also, I have another question. Is it possible to have a large primary key? For example PRIMARY KEY(id, name, last_name, age).
Thank you
Yes, you can have a large primary key ("composite key"). In your example, id
would then be the partition key, and name
, last_name
, age
are clustering keys. All fields combined make the primary key.
For a very good explanation of the different types (and naming) of keys, check out this SO answer.
This post gives an example of how to create a composite key:
system_manager.create_column_family(..., key_validation_class="CompositeType(UTF8Type, Int32Type)")
For your data then, I would guess:
system_manager.create_column_family(..., key_validation_class="CompositeType(Int32Type, UTF8Type, UTF8Type, Int32Type)")
I have not used pycassa myself, but the pycassa documentation has this example:
col_fam.insert('row_key', {'col_name': 'col_val'})
So I'll venture a guess for your case (adding a couple of columns for the sake of completeness):
col_fam.insert((id,name,last_name,age), {'firstname':first_name,'city':city})