Would like to populate some static test data via a CQLsh script.
This doesn't work: (device_id is UUID)
insert into devices (device_id, geohash,name, external_identifier, measures, tags) values ('c37d661d-7e61-49ea-96a5-68c34e83db3a','9q9p3yyrn1', 'Acme1', '936', {'aparPower','actPower','actEnergy'},{'make':'Acme'});
Bad Request: Invalid STRING constant (c37d661d-7e61-49ea-96a5-68c34e83db3a) for device_id of type uuid
I can't seem to find any CQL function to convert to proper type. Do I need to do this from a python script?
Thanks, Chris
A UUID is a Universally Unique ID used to avoid collisions. Cassandra 2.0.7 and later versions include the uuid () function that takes no parameters and generates a Type 4 UUID for use in INSERT or SET statements. You can also use a timeuuid type with a function like now (). They generate a Type 1 UUID.
Hence, a user can program Cassandra to work according to his requirement. When working on a Linux operating system, a user can start Cassandra Query Language Shell by executing simple command ‘cqlsh’. Whereas, when working in a Windows operating system, a user has to execute ‘python cqlsh’ to run cqlsh.
If you want to store data in bulk then inserting data from a CSV file is one of the nice ways. If you have data in a file so, you can directly insert your data into the database by using the COPY command in Cassandra.
insert into stuff (uid, name) values (nextuid (), 'my name'); As of Cassandra 2.0.7 you can just use uuid (), which generates a random type 4 UUID: Thanks for that you made my day! Thanks for the updated answer for newer versions of cassandra!
You shouldn't put the quotes around the UUID to stop it being interpreted as a string i.e.
insert into devices (device_id, geohash,name, external_identifier, measures, tags) values (c37d661d-7e61-49ea-96a5-68c34e83db3a,'9q9p3yyrn1', 'Acme1', '936', {'aparPower','actPower','actEnergy'},{'make':'Acme'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With