我可以 select 一个带有 CQL 的 Blob 列表吗?

Can I select a list of Blob with CQL?

我将所有 event_id 存储在 blob 类型中,并希望一次 select 多个 event_id

如果我一个一个发送查询,效果很好。喜欢这个:

SELECT JSON event_id, user FROM demo.events WHERE customer_id=1234 AND event_id=0x123123;

但是我想用IN子句同时查询多个event_id。我尝试了以下 CQL 但失败了:

SELECT JSON event_id, user FROM demo.events WHERE customer_id=1234 AND event_id in [0x123123, 0x456456, 0x789789];

给出错误信息

SyntaxException: line 1:106 no viable alternative at input 'event_id'

谁能告诉我是否可行?谢谢。

IN运算符requires tuble_literal on the right side of the expression. Tuples可以定义为()。在你的情况下 IN (x, y, z) 会起作用:

$ create table test.a (customer_id int, event_id blob, user text, PRIMARY KEY (customer_id, event_id));

$ insert into test.a (customer_id, event_id, user) values (1, 0x123123, 'a');
$ insert into test.a (customer_id, event_id, user) values (1, 0x123124, 'a');
$ insert into test.a (customer_id, event_id, user) values (1, 0x123125, 'a');

$ SELECT JSON event_id, user FROM test.a WHERE customer_id=1 AND event_id in (0x123123, 0x123124);

[json]
---------------------------------------
 {"event_id": "0x123123", "user": "a"}
 {"event_id": "0x123124", "user": "b"}

(2 rows)