I have written the following query in mysql using python
self.sql.get_value("delete from devices where asset_id = '{}'".format(VARIABLE))
When I run this I am getting an error:
Unable to retrieve data : 'NoneType' object has no attribute 'getitem'
Things I have tried:
Select query in same format works fine.
Checked if VARIABLE is Null, it is not
Tried this - delete from devices where asset_id = 'T1234'
Nothing worked. Any ideas on this would be helpful
Related
I am using psycopg2 library and iI made a query to select instances from a table in a database. I have run the code in a user interface program and it works however, I get an error when I run it in python. Here is the code:
find_id = 'SELECT "serial_number" FROM "LogFiles" WHERE "LogFiles"."user_name" = my product;'
cur.execute(find_id)
cur.fetchall()
ERROR happen in ^:
find_id='SELECT "serial_number" FROM "LogFiles" WHERE
"LogFiles"."user_name" = my ^product ;'
It seems that I need to deal with the space inside of a string as reading of the instance is stopped after my.
I have tried to use "my product" and '''my product''' and ''my product'' but they don't work as well.
Problem: I want to pick a field of index in elasticsearch and look for all the values against it. Like if I give a key I should get the value for that key and if that key exists more than once, so each whats the each value. Or even if I get one of the values would work for me.
How I am trying to work through it: Query the elasticsearch
I am trying to query my data from Elasticsearch;
r = es.search(index="test",body = {'query': {'wildcard': {'task_name': "*"}}})
I thought to load the data to a python object ( dictionary) to read a key values. However, when I try json.loads(r.json) it gives me an error : AttributeError: 'dict' object has no attribute 'json'.
I even tried with json.load(r) but the error remains the same.
I have someone's code who is not in the company and I want to get the data stored in mongo database which is using AsyncIOMotorClient. I have no experience with motor.
Problem:
I am able to get this:
AsyncIOMotorCursor(<pymongo.cursor.Cursor object at 0x7fbd87b45ca0>)
I know how to iterate over <pymongo.cursor.Cursor object at 0x7fbd87b45ca0>, but when I try to iterate over the above AsyncIOMotorCursor, I get the following error:
TypeError: 'AsyncIOMotorCursor' object is not iterable
Kindly help.
I'm trying to create a table in python using azure sql server, when i run this line of code below i get the following error:
'There is already an object named '***' in the database'.
def del_final_trades(new_table_name, cl_table_name, cp_table_name):
cursor.execute('''SELECT * INTO {newt} FROM {cl_t} INNER JOIN {cp_t} ON
{cl_t}.[CL_Trade ID] = {cp_t}.[CP_Trade ID]'''.format(newt=new_table_name, cl_t=cl_table_name,
cp_t=cp_table_name))
The error is correct, the table does exist but how do I drop the table if its NOT NULL and create a new one?
I understand the logic, I'm just struggling to put it into a working code, any help is appreciated!
You need to test if the table exists within a drop command:
DROP TABLE IF EXISTS [Table name]
I am new to python and its environment.
I am using in-memory sqllite DB.
I am trying to query one of the table on my source ( My-SQL ) and put that data to in-memory table for some calculations.
Here are the details :
Response from my source :
result = [(Decimal('69.00000'), 'MachineA', 9827), (Decimal('72.00000'), 'MachineB', 9831)]
Table in my sqllite ( In memory ) :
CREATE TABLE calculation (calculation_value DECIMAL(10, 5),source_name varchar(100),source_id bigint)
Following is the code which I am using to insert values from source to calculation table.
cur.executemany("INSERT INTO calculation VALUES(?,?,?)", result)
But I am facing error following error :
Exception Message : ('Error on line 335', 'InterfaceError', InterfaceError('Error binding parameter 0 - probably unsupported type.',))
Error is thrown on following line :
cur.executemany("INSERT INTO calculation VALUES(?,?,?)", result)
It will be great if somebody could help me to understand the root cause as well.