0

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")
Pelgoos
  • 33
  • 2

1 Answers1

2

In Python's Postgres library, you can interpolate values with %s and pass them as secondary arguments to execute.

my_cursor.execute("SELECT word FROM words WHERE id = %s", (my_id,))
Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116