0

I am trying to insert a tuple into mysql table using python, but tuple gets converted to list in mysql table.

settings: {
      'AEROSPIKE_CONN_SETTINGS' : {
        'hosts': [ ('aerospike.qgraph-vpc.io', 3000) ],
        'policies': {
           'timeout': 3000
        }
      }
    }
db = MySQLdb.connect(host='localhost', user='test', passwd='abcd', db='testdb')
cursor = db.cursor(MySQLdb.cursors.DictCursor)
insert_query = '''INSERT INTO test_table (`settings`) VALUES ('{}')'''.format(json.dumps(settings))
cursor.execute(insert_query)
cursor.connection.commit()

after executing the above code data gets inserted in the following format

settings:{ 
  "AEROSPIKE_CONN_SETTINGS": {
    "hosts": [["127.0.0.1", 3000]]
  }
}

It should be in the following format

settings:{ 
  "AEROSPIKE_CONN_SETTINGS": {
    "hosts": [("127.0.0.1", 3000)]
  } 
}

what is wrong or how can I insert in the expected format. I am reading the settings from mysql table in some other python component to connect to aerospike.

2
  • 1
    Please see this question and answers: stackoverflow.com/questions/15721363/… Commented Mar 27, 2017 at 16:55
  • This question isn't related to Aerospike. The fact that you are storing Aerospike configuration is just circumstantial. I suggest removing the tag. If Aerospike's python client rejects connecting with a list rather than tuple then ask that question separately. Commented Mar 27, 2017 at 17:24

1 Answer 1

2

There is no such thing as a tuple in JSON.

Note however, from the point of view of your Python code there is no practical difference between a list and a tuple. It's fine to let it be converted.

Sign up to request clarification or add additional context in comments.

1 Comment

yes it does make difference, while connecting to aerospike a tuple is request. I just converted list back to tuple in python code after reading from mysql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.