I do have a problem with inserting a string full of single quotes in my redshift (or postgresql) through python 3.6.
Here's my input:
In[330]: out
Out[330]:
"{'hourday': [17, 12, 18, 16], 'domain': ['google.ca', 'allrecipes.com'], 'device_type_id': [20], 'city': [90, 23, 42, 42]}"
It's a string and I tried by many means to insert it in my database thanks to this query:
cursor.execute("insert into table1 (message) VALUES (%s)",(out,))
I get a :
"psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block".
I tried almost everything to fix it : replacing single quotes with double single quotes (to escape single quotes in sql), putting backslash to escape in python. But every single time, there was a problem or with sql or with python. At some point I even had a :
TypeError: not all arguments converted during string formatting
It's killing me, please help me !
Thank you !
EDIT : Found the problem. The connection with my database was actually cut... I refreshed it and the code worked. Thank you !