I have a query such as:
select_query = [text(f) for f in fields]
with engine.connect() as conn:
query = select(*select_query, MyTable.id).select_from(
table(MyTable.__tablename__) ...
Everything works fine except when the field (inside select_query) is camelcase. Is there any function or directive to pass sqlalchemy so the camelcase fields do not break the select ?
You can get the behaviour that you want using the column construct (note the lower-case "c") rather than the text construct. Using column
tells SQLAlchemy that it is dealing with a column name rather than some arbitrary SQL fragment, so it can assume that the name is correctly cased and quote accordingly.
import sqlalchemy as sa
...
select_query = [sa.column(f) for f in fields]
...