https://stackoverflow.com/questions/48811239/how-to-set-alias-in-the-sqlalchemy-for-the-table
Another idea is to create a view in another schema pointing to the same table ... On Fri, May 12, 2023 at 3:48 PM Benjamin Taub <benjamin.t...@dataspace.com> wrote: > Thanks for the suggestion. > I thought about using an alias but came up with two problems: > 1) The FROM clause is auto-generated from SELECT clause, so I'm not sure > where I would add this alias > 2) All the aliases in the SELECT clause are also double-quoted. I believe > a single backquote would be more standard here. Perhaps there is a general > use on double quotes in SQL generation when backquotes would be more > appropriate? > > In my case, I can solve this by making sure that schema names always start > with a letter. This will prevent similar situations lurking elsewhere in my > code. But, I'll have to be careful that I don't mess up any code that deals > with previously-created schemas. Shouldn't be much of an issue today, > however. > > On Friday, May 12, 2023 at 4:38:23 PM UTC-4 S Mahabl wrote: > >> Is there alias you can give for >> >> *283ac7717fe770c5ed6d425c0c739cba".t_59a33cbea3617986d810e9fbae60ba19 XYZ* >> >> *?* >> >> On Fri, May 12, 2023, 3:30 PM Benjamin Taub <benjam...@dataspace.com> >> wrote: >> >>> 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 >>> >>> >>> -- >>> SQLAlchemy - >>> The Python SQL Toolkit and Object Relational Mapper >>> >>> http://www.sqlalchemy.org/ >>> >>> To post example code, please provide an MCVE: Minimal, Complete, and >>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >>> description. >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "sqlalchemy" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to sqlalchemy+...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/sqlalchemy/76d38390-e17f-4b90-a438-ee078944b5ffn%40googlegroups.com >>> <https://groups.google.com/d/msgid/sqlalchemy/76d38390-e17f-4b90-a438-ee078944b5ffn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/7022e294-b5bc-493a-b24f-b3f1939741ban%40googlegroups.com > <https://groups.google.com/d/msgid/sqlalchemy/7022e294-b5bc-493a-b24f-b3f1939741ban%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAOV%2B3C1sng3V%2BRq_8MMVH%3D-ho%3DiKUqMSVjQp2kavaRc70dtH5g%40mail.gmail.com.