Python SQL query using dynamic table names

The reason is that I recently wrote a python script. Since the sub-database and sub-table are used, the database and table names need to be dynamically calculated according to the sub-table fields. At first, the %s placeholder was used directly in SQL. Later, it was found that an error was reported and the SQL statement was prompted. The syntax is wrong. After a closer look, I found that the single quotation mark was directly added to the library name and table name, resulting in a syntax error, but I didn’t want to splicing SQL directly. The solution The solution is relatively simple, go directly to the code: db_name = sharding(‘db’, ‘database’, store_id, 10, 4, -1) […]

This article is reproduced from: https://www.lifengdi.com/archives/article/tech/3870
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment