I'm working on postgresql and doing security check about SQL injection. I'm refactoring my code to avoid SQL injection.
I want to do the average of a column named "television" Here my code :
with connection.cursor() as cursor:
sql.append(
f"""SELECT COUNT(*),
AVG(%s)
FROM dataset"""
)
values.append(target)
cursor.execute(sql, values)
If i print values:
['television']
But i got error :
LINE 3: AVG('television'),
It's look like simple quote are problem here, i need to have AVG("television"). There is a way to force simple quote to double quote ?
I tried to parameter it before like that :
new_target = f'"{target}"'
with connection.cursor() as cursor:
sql.append(
f"""SELECT COUNT(*),
AVG(%s)
FROM dataset"""
)
values.append(new_target)
cursor.execute(sql, values)
But got almost same error:
AVG('"television"'),