I have code that worked under SQLAlchemy 1.4 but recently upgraded to 2. I am using the add_columns() method to add columns to an existing SQL statement. The resultant queries sometimes, but not always, crash. I believe the issue happens when the schema/database name (I'm using MySQL) starts with a number. When the schema name starts with a letter, the result runs fine. However, when it starts with a number, the query double-quotes the schema name, causing the query to crash.
Here is an example...
My code: sql = sql.add_columns(self.tbl.c[field])
When the schema holding self.tbl.c[field] starts with a letter (c6961a19b7ed031ce902f056c725b3e3), the following SQL is generated:
SELECT NULL AS "Application Id", NULL AS "First Name", NULL AS "Last Name", NULL AS "Email", c6961a19b7ed031ce902f056c725b3e3.t_31392eb2e6980f4d5082b7861182f2b4.master_key
FROM c6961a19b7ed031ce902f056c725b3e3.t_31392eb2e6980f4d5082b7861182f2b4
However, when the schema name starts with a number (283ac7717fe770c5ed6d425c0c739cba), the following SQL results:
SELECT NULL AS "Application Id", NULL AS "First Name", NULL AS "Last Name", NULL AS "Email", "283ac7717fe770c5ed6d425c0c739cba".t_59a33cbea3617986d810e9fbae60ba19.master_key
FROM "283ac7717fe770c5ed6d425c0c739cba".t_59a33cbea3617986d810e9fbae60ba19
Note the double quotes around the schema name. This second SQL crashes as invalid. Back quotes (`) would probably work fine in this situation, and could be helpful, but double quotes (") are, I think, the cause of my problem.
Is there some parameter or assumption that I'm not understanding, or did I find a bug?
Thank you!
Ben