cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rajesh Radhakrishnan <>
Subject Getting code=2200 [Invalid query] message=Invalid column name ... while executing ALTER statement
Date Fri, 13 Nov 2015 11:14:05 GMT


I am using Cassandra 2.1.5 in a cluster of two nodes (running CentOS) and using Python driver
to connect to Cassandra.
My Python code snippet is show here:

import time, os, datetime, keyword
import uuid
from cassandra.cluster import Cluster
import os.path, sys
from cassandra.auth import PlainTextAuthProvider
       auth_provider = PlainTextAuthProvider(username, password)
       cluster = Cluster([node1,node2],auth_provider=auth_provider)
       session = cluster.connect();

        session.execute("CREATE table IF NOT EXISTS test.iau ("
                    "id uuid, "
                    "sample_id text, "
                    "PRIMARY KEY (sample_id) )");

        print " \n created the table"

        sqlInsertSampleIdUid = "INSERT INTO test.iau (id, sample_id) VALUES ("+str(uuid.uuid1())+",'sample123')"
        print " \n Inserted main ids into the table"

        colNames =['col1','col2','col3','col4','col5','col6','col7','col8','col9']

        for colName in colNames :

            sqlAlterStatement1 = " ALTER TABLE test.iau ADD "+colName+" text"
            print sqlAlterStatement1
            sqlAlterStatement1 = None

        print " Altered tables :: "
        # ----------------------------------------
        count = 0
        for colName in colNames :
            count = count +1
            sqlUpdateGeneDetection = " UPDATE test.iau SET "+colName+" = '"+str(count)+"'
WHERE sample_id = 'sample123'"
            sqlUpdateGeneDetection = None

        print " Updated tables :: "

Very rarely this code works, but most of the time it fails when it reach ALTER statement.
FYI, I tried preparedstatement with binding in INSERT, UPDATE statements too.

The error with output is shown here:

created the table

 Inserted main ids into the table
 ALTER TABLE test.iau ADD col1 text
 ALTER TABLE test.iau ADD col2 text
 ALTER TABLE test.iau ADD col3 text
 ALTER TABLE test.iau ADD col4 text
 ALTER TABLE test.iau ADD col5 text
 ALTER TABLE test.iau ADD col6 text
 ALTER TABLE test.iau ADD col7 text
 ALTER TABLE test.iau ADD col8 text
 ALTER TABLE test.iau ADD col9 text

Traceback (most recent call last):
  File "", line 313, in test_insert_data
  File "/usr/local/lib/python2.7/site-packages/cassandra/", line 1405, in execute
    result = future.result(timeout)
  File "/usr/local/lib/python2.7/site-packages/cassandra/", line 2976, in result
    raise self._final_exception
InvalidRequest: code=2200 [Invalid query] message="Invalid column name col9 because it conflicts
with an existing column"

Ran 1 test in 9.856s

But when I checked the table using CQL col9 is not there.

Is there' schema' refresh issue or is it bug in Cassandra 2.1.5?

Thank you.
Kind regards
Rajesh R

The information contained in the EMail and any attachments is confidential and intended solely
and for the attention and use of the named addressee(s). It may not be disclosed to any other
person without the express authority of Public Health England, or the intended recipient,
or both. If you are not the intended recipient, you must not disclose, copy, distribute or
retain this message or any part of it. This footnote also confirms that this EMail has been
swept for computer viruses by Symantec.Cloud, but please re-sweep any attachments before opening
or saving.
View raw message