the .fullname attribute is not used directly in SQL statements, when a schema 
or table name requires quoting the compiler will apply them as needed.

from sqlalchemy import Column 
from sqlalchemy import String
from sqlalchemy.dialects import mysql
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session

Base = declarative_base()


class SomeTable(Base):
    __tablename__ = "3table"

    id = Column(String, primary_key=True)

    __table_args__ = {"schema": "4schema"}


s = Session()

print(s.query(SomeTable).statement.compile(dialect=mysql.dialect()))

output:

SELECT `4schema`.`3table`.id 
FROM `4schema`.`3table`




On Tue, Dec 22, 2020, at 12:35 PM, Benjamin Taub wrote:
> schema.py defines a variable fullname for tables as follows:
> 
> *if *self.schema *is not None*:
>     self.fullname = *"%s.%s" *% (self.schema, self.name)
> *else*:
>     self.fullname = self.name
> 
> However, this fails for me in some cases, apparently when my table or schema 
> name starts with a number. To address this, shouldn't self.fullname be 
> surrounded by delimiters (e.g. "`%s`.`%s`")?
> 
> FWIW, I'm working in MySQL.
> 
> Thanks!
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/4c572cf3-992a-4527-a2a9-500bc48170e5n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/4c572cf3-992a-4527-a2a9-500bc48170e5n%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/47c97c98-23d1-42ea-be54-f65c33543c81%40www.fastmail.com.

Reply via email to