Start here
How to Pass a Variable in an SQL Query in Python
Pass a Python variable into an SQL query safely with placeholders. Examples for sqlite3, psycopg2, PyMySQL and pyodbc, plus lists and named values.
Writing SQL
Passing variables and lists into SQL queries from Python, with the string handling around them.
Start here
Pass a Python variable into an SQL query safely with placeholders. Examples for sqlite3, psycopg2, PyMySQL and pyodbc, plus lists and named values.
Use an f-string to put a variable into text in Python. Learn why string building is unsafe for SQL and how placeholders keep values out of the query.
Match several text values in an SQL IN clause from Python. One placeholder per string, empty-list handling, PostgreSQL arrays and SQL Server splitting.
Write the text I love you as a Python string, handle quotes inside it, and save it to SQL safely with a placeholder instead of string building.
vars() returns an object's attribute dictionary, or the local names with no argument. See how its output can supply named values to an SQL query.
Related topics