Linked Questions

Popular Questions

Why do parentheses in an IN clause affect the result of a SELECT query?

Asked by At

I'm trying to execute a SELECT query which contains an IN clause with the C# CQL driver on Cassandra 2.0.

I have a simple table that looks like

CREATE TABLE test.in_clause (key_val text PRIMARY KEY);

with a single value

INSERT INTO test.in_clause (key_val) VALUES ("some value");

I can then use a PreparedStatement to execute my query.

Cluster cluster = Cluster.Builder ().AddContactPoint ("localhost").WithPort (9048).Build ();
ISession session = cluster.Connect ("test");
var ps = session.Prepare ("SELECT * FROM in_clause WHERE key_val IN ?");
var list = new List<string> () { "some value", "something", "else" };
var bs = ps.Bind (list);
var rs = session.Execute (bs);
foreach (var row in rs.GetRows ()) {
    Console.WriteLine (row.GetValue<string> ("key_val"));

and this prints the single row in the table.

However, if I add parentheses () around the bind placeholder ?, no results are found. That is, if I use

var ps = session.Prepare ("SELECT * FROM in_clause WHERE key_val IN (?)");
//                                                      these guys: ^ ^

the RowSet returned by ISession.Execute contains no rows. Why does this happen?

I'm not exactly sure how to interpret the red parentheses in the CQL documentation for SELECT which might explain this behavior. It might have something to do with term tuples, but those are only present in Cassandra 2.1.

Related Questions