It should be simple, bit I've spent the last hour searching for the answer. This is using psychopg2 on python 2.6.
I need something like this:
special_id = 5
sql = """
select count(*) as ct,
from some_table tbl
where tbl.id = %(the_id)
"""
cursor = connection.cursor()
cursor.execute(sql, {"the_id" : special_id})
I cannot get this to work. Were special_id
a string, I could replace %(the_id)
with %(the_id)s
and things work well. However, I want it ot use the integer so that it hits my indexes correctly.
There is a surprising lack of specific information on psychopg2 on the internet. I hope someone has an answer to this seemingly simple question.