Apply the wildcards to the parameter, not the SQL:
cursor.execute("SELECT * FROM posts WHERE tags LIKE ?", (f'%{tag}%',))
The ? SQL parameter interpolation adds quoting for you, so your query ends up as '%'value'%', which is not valid SQL.
0
votes
Remove the %:
cursor.execute("SELECT * FROM posts WHERE tags LIKE ?", (tag,))
This should format it as you wanted. For example, if tag == 'test' the full query would be:
SELECT * FROM posts WHERE tags LIKE 'test'
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more