ResponseError : Expected 4 or 0 byte int

后端 未结 1 410
南方客
南方客 2021-02-08 02:31

I am trying cassandra node driver and stuck in problem while inserting a record, it looks like cassandra driver is not able to insert float values.

Problem: When         


        
相关标签:
1条回答
  • 2021-02-08 02:39

    Following words are as it is picked from cassandra node driver data type documentation

    When encoding data, on a normal execute with parameters, the driver tries to guess the target type based on the input type. Values of type Number will be encoded as double (as Number is double / IEEE 754 value).

    Consider the following example:

    var key = 1000;
    client.execute('SELECT * FROM table1 where key = ?', [key], callback);
    

    If the key column is of type int, the execution fails. There are two possible ways to avoid this type of problem:

    1. Prepare the data (recommended) - prepare the query before execution

      client.execute('SELECT * FROM table1 where key = ?', [key], { prepare : true }, callback);

    2. Hinting the target types - Hint: the first parameter is an integer`

      client.execute('SELECT * FROM table1 where key = ?', [key], { hints : ['int'] }, callback);

    If you are dealing with batch update then this issue may be of your interest.

    0 讨论(0)
提交回复
热议问题