Search code examples
gocql

multiple in clause gocql not executing


Problem with running a query from gocql but it runs okay from the console.

  DELETE            
    FROM 
        honda.car_v1 
    WHERE 
        (id in ?)
        AND
        (user_id in ?)

I tried running this in cql console, it runs perfectly but when i run it via https://github.com/gocql/gocql it does not give any error, yet the rows are still there. I wonder what did i do wrong.


Solution

  • id := []int{10,20,30}

    userData := []int{1,2,3,4}

    It has nothing to do with the gocql itself. turns out the way I convert the arrays into comma separated values turned the list into string which is invalid because

    id is now "10,20,30" and userData is now "1,2,3,4" and it's sent to the query like this

    DELETE            
    FROM 
        honda.car_v1 
    WHERE 
        (id in '10,20,30')
        AND
        (user_id in '1,2,3,4')
    

    where i needed them to be like

    DELETE            
    FROM 
        honda.car_v1 
    WHERE 
        (id in 10,20,30)
        AND
        (user_id in 1,2,3,4)
    

    so i just do a simple string formatting to solve the problem.