50

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

giampaolo
  • 6,906
  • 5
  • 45
  • 73
Chris H
  • 665
  • 1
  • 7
  • 10
  • 1
    You should accept the answer as it definitely solves your issue (thinking about the thank you note) – Bruce Oct 08 '13 at 08:53

2 Answers2

94

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'});
Richard
  • 11,050
  • 2
  • 46
  • 33
  • is there possibility to insert output of uuid() of function into a text field? e.g. insert into devices(....) values ( cast (uuid() as text), '9q9p3yyrn1', ...) – Peter Feb 15 '18 at 16:00
-1

Alternate: Use uuid() function. I have tested this in DevCenter 1.6.0.

insert into CHANGE_LOG (someid, modifieddatetime, snum, gnum, source) 
values ( uuid() , '2000-12-12 08:00:00', '21A', '', 'system');
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
harish
  • 43
  • 4