How can I use a list of values with the IN operator in a WHERE clause?

Jesse W at Z - Given up on SE

I'm trying to execute a query like this, using the JavaScript driver:

client.execute('SELECT * FROM zhos_dev.jw_testing WHERE a IN ?', [['foo', 'foo1']], {prepare: true})

It gives me: ResponseError: line 0:-1 mismatched input '<EOF>' expecting ')'.

My version is: [cqlsh 3.1.8 | Cassandra 1.2.19 | CQL spec 3.0.5 | Thrift protocol 19.36.2]

The table was created and populated with the following CQL:

CREATE TABLE zhos_dev.jw_testing (a text PRIMARY KEY, b text);
INSERT INTO zhos_dev.jw_testing (a, b) VALUES ('foo', 'bar');
INSERT INTO zhos_dev.jw_testing (a, b) VALUES ('foo1', 'bar1');
INSERT INTO zhos_dev.jw_testing (a, b) VALUES ('foo2', 'bar2');
Valerie Parham-Thompson

I've reproduced this in the same version: [cqlsh 3.1.8 | Cassandra 1.2.19 | CQL spec 3.0.5 | Thrift protocol 19.36.2]

  name: 'ResponseError',
  info: 'Represents an error message from the server',
  message: "line 0:-1 mismatched input '<EOF>' expecting ')'",
  code: 8192,
  query: 'SELECT name, color FROM keyspace1.dresses WHERE id IN ?'

The "IN" clause works fine as early as Cassandra 2.1: [cqlsh 5.0.1 | Cassandra 2.1.21 | CQL spec 3.2.1 | Native protocol v3]

Connected to cluster with 1 host(s): ["127.0.0.1:9042"]
Azul Dress

Test table/data:

CREATE KEYSPACE keyspace1 WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1 };

CREATE TABLE keyspace1.dresses (id text, color text, name text, size int, PRIMARY KEY (id, color));

insert into dresses (id, color, name, size) values ('mon1', 'blue', 'Blue Dress', 12);
insert into dresses (id, color, name, size) values ('mon2', 'blue', 'Azul Dress', 12);
insert into dresses (id, color, name, size) values ('can1', 'green', 'Green Dress', 12);
insert into dresses (id, color, name, size) values ('can2', 'verde', 'Verde Dress', 12);

And code:

const cassandra = require('cassandra-driver');

const client = new cassandra.Client({ contactPoints: ['127.0.0.1'], localDataCenter: 'datacenter1' });
client.connect(function (err) {
  if (err) return console.error(err);
  console.log('Connected to cluster with %d host(s): %j', client.hosts.length, client.hosts.keys());
});

client.execute('SELECT name, color FROM keyspace1.dresses WHERE id IN ?', [ ['mon2'] ], 
    { prepare: true}, 
    function (err, result) {
          if (err) return console.error(err);
          const row = result.first();
          console.log(row['name']);
});

Since the node.js driver is only supported in Cassandra 2.1 and above (https://docs.datastax.com/en/developer/nodejs-driver/4.1/faq/#which-versions-of-cassandra-does-the-driver-support), I don't think the Cassandra or driver projects would take a bug request. Can you upgrade to at least 2.1?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can i use an array of values inside where clause in knex?

How can i use IFNULL in Where clause

How i can use If Else in where clause

Can I use an or ( || ) in a where clause?

How to use an operator in where clause with an optional include?

how can i use multiple where clause In codeigniter?

How can I use a variable inside the where clause?

How can I use COALESCE() in WHERE clause optimally?

How can I use hasColumn with where clause in knex

How can i use SQL where clause with multiple parameters

How can I use a Expression tree in an EF Where() clause with join?

If I can't use aggregate in a where clause, how to get results

How can I use the LAG function combined with a WHERE clause?

How can I use WHERE clause in this SQL query?

How can I use data_type in where clause

How do I create a variable/parameter that is a string of values in SQL SSMS that I can use as a substitute in my where clause?

SQL: Can I convert a string value of a "<" operator into an operator in a where clause?

How to use IN operator with AND operator in WHERE clause in SQL...?

"SQL Question: How can I store multiple wildcard strings in a table and pass them on to the LIKE operator in a where clause"

How to use same list twice in WHERE clause?

How can you use NULLIF in the where clause?

How can I combine date with WHERE clause

In yii2 query builder how to use in operator with where clause

How to use AND operator in update operation for where clause in Android Sqlite?

How to convert SQL query to PHP and use AND operator in WHERE clause

Is it posible to use multiple values from a json list in a mysql where clause?

How do I use multiple values from the same column in the WHERE clause?

When I use the WHERE clause my basic entity values are NULL

How do I tell Dapper to use varchar for a list of params in a "WHERE" clause that uses "IN"?