Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlalchemy using an escaped table name yields invalid query #480

Open
cleboo opened this issue Oct 8, 2021 · 0 comments
Open

sqlalchemy using an escaped table name yields invalid query #480

cleboo opened this issue Oct 8, 2021 · 0 comments

Comments

@cleboo
Copy link

cleboo commented Oct 8, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant