Skip to content

SQLAlchemy Connection as as_string() argument -- TypeError: argument 2 must be a connection or a cursor #1606

Closed Answered by skwzrd
skwzrd asked this question in Q&A
Discussion options

You must be logged in to vote

I've made a few attempts with these suggestions, and couldn't figure it out. A discussion has been opened at sqlalchemy/sqlalchemy#10222.

Edit:

From the SA discussion, we got the following code go work. Just need to escape wildcards (%%) and use exec_driver_sql().

with engine.connect() as conn:
    sql_string = sql.SQL(
        """select * from {0} where {1} like 'A%%' limit 5;"""
    )
    sql_string = sql_string.format(sql.Identifier(table_name), sql.Identifier(column_name))

    results = conn.exec_driver_sql(sql_string)
    for result in results:
        print(result)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@skwzrd
Comment options

Answer selected by skwzrd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants