Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-14 Thread r...@rosenfeld.to
Thanks. That worked, too. On Tuesday, April 13, 2021 at 8:46:34 AM UTC-5 Mike Bayer wrote: > the next section at > https://docs.sqlalchemy.org/en/14/orm/mapping_columns.html#automating-column-naming-schemes-from-reflected-tables > > shows how to automate intercepting of reflected columns,

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-13 Thread Mike Bayer
the next section at https://docs.sqlalchemy.org/en/14/orm/mapping_columns.html#automating-column-naming-schemes-from-reflected-tables shows how to automate intercepting of reflected columns, so you could do this: from sqlalchemy import event @event.listens_for(metadata, "column_reflect") def

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-13 Thread r...@rosenfeld.to
Thanks for the documentation. Sorry, but I'm not certain how to apply that in my case. Since I am mapping to an existing table, how could I reference the object attribute with an illegal name in Python? Do I combine getattr with the documentation as below? class Student(Model):

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-12 Thread Mike Bayer
besides the idea of using getattr(), as these are object attributes it's probably a good idea to name them differently from those columns. See the docs at https://docs.sqlalchemy.org/en/14/orm/mapping_columns.html#naming-columns-distinctly-from-attribute-names for strategies on how to achieve

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-12 Thread r...@rosenfeld.to
Yep. That seems fine. Thanks. SQLAlchemy doesn't escape or quote the name. I checked using inspection = inspect(Student) return [c_attr.key for c_attr in inspection.mapper.column_attrs] On Monday, April 12, 2021 at 5:55:07 AM UTC-5 Richard Damon wrote: > On 4/12/21 12:29 AM, Rob

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-12 Thread Richard Damon
On 4/12/21 12:29 AM, Rob Rosenfeld wrote: > Hi All, > > I'm using SQLAlchemy to access a legacy MSSQL database.   I'm using > the autoload feature to load the schema from the database. > > In this example I'd like to read data out of the column named > "1st_period" in the database.   The following

[sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-11 Thread Rob Rosenfeld
Hi All, I'm using SQLAlchemy to access a legacy MSSQL database. I'm using the autoload feature to load the schema from the database. In this example I'd like to read data out of the column named "1st_period" in the database. The following query shows the SQL I'd need. But trying to access a