Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
This thing is working:
my_cursor.execute("SELECT word FROM words WHERE id = 45")
How can I make this thing working?
my_id = 45 my_cursor.execute("SELECT word FROM words WHERE id = my_id")
psycopg2
my_cursor.execute(f"SELECT word FROM words WHERE id = {my_id}")
In Python's Postgres library, you can interpolate values with %s and pass them as secondary arguments to execute.
%s
execute
my_cursor.execute("SELECT word FROM words WHERE id = %s", (my_id,))
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
psycopg2the docs spell it out Passing parametersmy_cursor.execute(f"SELECT word FROM words WHERE id = {my_id}")with modern string formatting.