It's not that important, so I'm just curious to know the following (Python 2.7):
I just started using psycopg and reading through documents, they always use strings (% s) and tuples to pass values to the request.
Variable placeholder must always be% s
So, consider the following example -
In a table named "test" with the fields value_1 (varchar) and value_2 (int), the query is created as:
value_1 = "test"
value_2 = "100"
cur.execute("INSERT INTO test (value_1,value_2) VALUES (%s,%s)",\
(value_1,value_2))
My question is, is this a bad practice or is it even problematic to use the 'format' method instead:
cur.execute("INSERT INTO test (value_1,value_2) VALUES ('{value1}',{value2})".\
format(value1=value_1,value2=value_2))
What do you say, based on your experience, is it really dangerous or problematic?
user2113422
source
share