Fetch Posts by Id SQL Python: Part #41 Python API Course

preview_player
Показать описание
Enjoy this completely free 19 hour course on developing an API in python using FastAPI. We will build a an api for a social media type app as well as learn to setup automatic tests and deploy the app and finally we'll also learn how to setup a CI/CD workflow using github actions.

Full Course Playlist:

Github Repo:

If you like this video please subscribe to this channel. Don't let me go hungry! 🎁

▬▬▬▬▬▬ Support this garbage Channel 🍒 ▬▬▬▬▬▬

▬▬▬▬▬▬ Stalk me on Social Media 😲 ▬▬▬▬▬▬
Рекомендации по теме
Комментарии
Автор

4:51 I think the problems that occur are due to str(id), with a comma making it a tuple while without it, it's not a tuple.
i.e:
(2, ) # is a tuple
2, # is a tuple
(2) is not a tuple

eonstar
Автор

The comma problem is because the "(parameters)" passed after the cursor SQL string are expecting a tuple. (str(id), ) creates a tuple whereas (str(id)) is not a tuple.

zeektm
Автор

Easy fix willl be to add ", " Example : cursor.execute("""SELECT * FROM posts WHERE id = (%s) """, (id, ))

shashankbhandari
Автор

Explanation: (id) is not a tuple; it is just the integer id enclosed in parentheses. To create a single-element tuple, you need to add a comma, like this: (id, )

cursor.execute("""SELECT * FROM posts WHERE id = %s""", (id, ))

arunkumaralagarsamy
Автор

it accepts tuple format, (, ) => syntax for one element

akshaynitin