close
Skip to content

Dash/Minus in column name causes UNBOUND_SQL_PARAMETER in bind values #368

@Floowey

Description

@Floowey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions