PyMySQL Cannot Replace Variable in Statement When Executing SQL

Viewed 34

I'm somewhat stuck here. I'm using Python 3.9.0 with PyMySQL (0.10.1) and trying to create a function that creates a table. Every time I run the following statement:

        table = 'test'

        cursor = db.cursor()

        statement = """CREATE TABLE IF NOT EXISTS `%s` (
          `id` int NOT NULL AUTO_INCREMENT,
          `client_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
          `client_secret` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
          `security_token` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"""

        cursor.execute(statement, (table))

The table is created each time, but it creates it inside single quotes like 'test'. I need it to be created without quotes of course.

Anyone have any insights into why this is happening? Any help is much appreciated.

Thank you, Marko

0 Answers
Related