0

How to use bind variables in a select statement.

When I am using it directly it is retrieving the values as below.

select event_hour 
from stage_insight.insight_hourly_ts
where tag_id='UP247490.UPSYSCPWLV001A'
LIMIT 1;

How to use it dynamically?

select event_hour 
from stage_insight.insight_hourly_ts 
where tag_id = ? ;

For the second one, an error is displayed like, wrong amount of bind variables.... I am working with DataStax DevCenter. So, here I am trying to fetch the values directly from CassandraDB.

ResponseError: Invalid amount of bind variables\n  
  at FrameReader.readError (D:\\EACApp\\eac-app-management\\node_modules\\cassandra-driver\\lib\\readers.js:326:15)\n
    at Parser.parseBody (D:\\EACApp\\eac-app-management\\node_modules\\cassandra-driver\\lib\\streams.js:194:66)\n
    at Parser._transform (D:\\EACApp\\eac-app-management\\node_modules\\cassandra-driver\\lib\\streams.js:137:10)\n
    at Parser.Transform._read (_stream_transform.js:205:10)\n    at Parser.Transform._write (_stream_transform.js:193:12)\n
    at writeOrBuffer (_stream_writable.js:352:12)\n    at Parser.Writable.write (_stream_writable.js:303:10)\n 
   at Protocol.ondata (_stream_readable.js:719:22)\n    at Protocol.emit (events.js:315:20)\n 



cqlsh> show version
[cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Sumant
  • 21
  • 2
  • Is this using the Cassandra node.js driver? – Aaron Jul 25 '22 at 17:18
  • I am not sure but as per the log i think it is using – Sumant Jul 25 '22 at 18:43
  • Oh wait, you're using DevCenter? DevCenter won't let you use dynamic variables. You can only do that with a language driver (Java, Python, node.js, etc.). – Aaron Jul 25 '22 at 19:18
  • But application is based on node js. Represents an error message from the server',\n code: 8704,\n coordinator: '127.0.0.1:9042',\n query: 'SELECT * from user_request_by_country_by_processworkflow WHERE created_on <= ? ALLOW FILTERING'\n}" above query we are using from node js application to fetch data but it is returning error – Sumant Jul 26 '22 at 02:35
  • Use Apache Zeppelin that supports bindings – Alex Ott Jul 26 '22 at 14:34

1 Answers1

0

It isn't possible to use bind variables in DevCenter since they are only available when using prepared statements programatically.

If you are using bind variables in your Node.js app, my best guess is that you are passing the query parameters incorrectly although it's hard to say since you haven't provided enough information about your issue. In fact, the information you provided in your original question do not match what you've stated in the comments section.

Since you're new to Stack Overflow, a friendly suggestion that you learn how to ask good questions. The general guidance is that you (a) provide a good summary of the problem that includes software/component versions, the full error message + full stack trace; (b) describe what you've tried to fix the problem, details of investigation you've done; and (c) minimal sample code that replicates the problem.

In your case, you need to provide:

  • the CQL table schema
  • the driver you're using + version
  • minimal sample code

If you don't provide sufficient information in your questions, you are less likely to get help from forums or not get the right answers. Cheers!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23