Skip to content

sqlalchemy using an escaped table name yields invalid query #480

Description

@cleboo

Hi!

I encountered an issue with the impala-sqlalchemy connector when querying a table with a name that contains a reserved word.

The table is named "reserved.name" and usually can be queried using backticks like so:

SELECT `reserved`.name.column_1, `reserved`.name.column_2  FROM `reserved`.name;

To load the table into sqlalchemy I then use

def impala_conn():
    return connect(
        host='localhost'
    )

engine = create_engine('impala://', creator=impala_conn, echo=True)
metadata = MetaData(engine)
table = Table(`reserved`.name, metadata, autoload=True)

table contains a correct description of the table.

However when trying to query the table with

stmt = select(table).limit(100)
engine.execute(stmt)

the query escapes the already escaped table name again, leading to a query that fails:

SELECT ``reserved`.name`.column_1, ...
       ^
Encountered: EMPTY IDENTIFIER
Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, LEFT, NOT, NULL, REPLACE, RIGHT, STRAIGHT_JOIN, TRUNCATE, TRUE, IDENTIFIER

CAUSED BY: Exception: Syntax error

Is there a way to avoid the additional escaping during the query?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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