I am working with the following code in python, calling a PostgreSQL query using subprocess :
import subprocess claimer_name = 'a_name' startdate = '2014-04-01' enddate = '2018-04-01' data = subprocess.check_output(['/usr/bin/psql -U user_name "SELECT c.asset_id, c.video_id, c.claim_id, c.claim_date FROM db.claim c JOIN db.claim_history h ON c.claim_id = h.claim_id JOIN db.users_email e ON LOWER(e.email) = LOWER(h.email) JOIN m.auth_user u ON e.user_id = u.id WHERE h.list_order = 1 AND c.claim_origin = 'Descriptive Search' AND c.claim_date >= \"%s\" AND c.claim_date < \"%s\" AND concat(u.first_name, concat(chr(32), u.last_name)) = \"%s\""' % (startdate, enddate, claimer_name)], shell=True)
How can I avoid single quotes around Descriptive Search? Running this as-is code gives the error Only ASCII characters are allowed in an identifier.
I tried:
[''Descriptive Search''][\'Descriptive Search\'][""Descriptive Search""][concat('Descriptive', concat(chr(32), 'Search'))]
and variable assignment: i = 'Descriptive Search' , and then c.claim_origin = \"%s\" .
However, these attempts give the same ASCII characters error. Using string formatting is great for my other variables ( startdate , enddate , claimer_name ), and I'm at a dead end why it doesn't work for the Descriptive Search string.
Using PostgreSQL 9.3.
Any help or points in the right direction would be wonderful; thanks!
source share