I am trying to build an ORM over existing database (which I have no architectural influence over). I am running into an issue where some of the column names have a "-" in their name. In short, this syntax is carried over into the bound parameter where it causes issues.
This trimmed down example outlines this issue:
class Person(Base):
__tablename__="persontable"
id: Mapped[int] = mapped_column(name="id", primary_key=True)
first_name: Mapped[str] = mapped_column(name="first-name")
Note how the column name in the table has a dash in it.
Now, if I build a query that would parametize this value and run it:
stmt = select(Person).where(Person.first_name=="John")
# print(stmt):
# SELECT persontable.`id`, persontable.`first-name` FROM persontable WHERE persontable.`first-name` = :first-name_1
with Session.session() as session:
johns = session.scalars(stmt)
An error is raised
sqlalchemy.exc.DatabaseError: (databricks.sql.exc.ServerOperationError) [UNBOUND_SQL_PARAMETER] Found the unbound parameter: first.
The way I see it is that :first-name_1 is not taken as is, but the - is interpreted as a subtraction operator.
I assume this is an oversight in implementing the dialect. I am hoping someone could assist with a workaround or implement a solution. Please note that renaming the column on the table directly is not an option for me.
I am trying to build an ORM over existing database (which I have no architectural influence over). I am running into an issue where some of the column names have a "-" in their name. In short, this syntax is carried over into the bound parameter where it causes issues.
This trimmed down example outlines this issue:
Note how the column name in the table has a dash in it.
Now, if I build a query that would parametize this value and run it:
An error is raised
sqlalchemy.exc.DatabaseError: (databricks.sql.exc.ServerOperationError) [UNBOUND_SQL_PARAMETER] Found the unbound parameter: first.The way I see it is that
:first-name_1is not taken as is, but the-is interpreted as a subtraction operator.I assume this is an oversight in implementing the dialect. I am hoping someone could assist with a workaround or implement a solution. Please note that renaming the column on the table directly is not an option for me.