Skip to content

Problem with any SQL query due to pandas/SQLAlchemy #529

Closed
@ricardocarvalhods

Description

@ricardocarvalhods

Hello,

If you install the lib from scratch today, it gives error on basically any SQL query it tries to execute.
See the error below.

According to this issue:

  • Passing a string to execute in SQLAlchemy has been deprecated in 2.0.0 (January 26th, 2023)
  • And pandas passes down the string without wrapping it in text()

That's probably the case, I tried SQLAlchemy==1.4.46 and the error was gone.

Error:

File "/home/vscode/.local/lib/python3.9/site-packages/snsql/sql/reader/pandas.py", line 148, in execute
    q_result = sqldf(clean_query(query), locals())
  File "/home/vscode/.local/lib/python3.9/site-packages/pandasql/sqldf.py", line 156, in sqldf
    return PandaSQL(db_uri)(query, env)
  File "/home/vscode/.local/lib/python3.9/site-packages/pandasql/sqldf.py", line 61, in __call__
    result = read_sql(query, conn)
  File "/home/vscode/.local/lib/python3.9/site-packages/pandas/io/sql.py", line 590, in read_sql
    return pandas_sql.read_query(
  File "/home/vscode/.local/lib/python3.9/site-packages/pandas/io/sql.py", line 1560, in read_query
    result = self.execute(*args)
  File "/home/vscode/.local/lib/python3.9/site-packages/pandas/io/sql.py", line 1405, in execute
    return self.connectable.execution_options().execute(*args, **kwargs)
  File "/home/vscode/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1412, in execute
    raise exc.ObjectNotExecutableError(statement) from err
sqlalchemy.exc.ObjectNotExecutableError: Not an executable object: 'SELECT COUNT(*) AS keycount, marital_status AS marital_status, SUM(age) AS sum_age FROM ( SELECT marital_status AS marital_status, CASE WHEN age < 0 THEN 0 WHEN age > 110 THEN 110 ELSE  age END AS age FROM df_for_diffpriv1234 ) AS per_key_all GROUP BY marital_status'

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