Incorrect syntax error on read_sql
See original GitHub issueI am getting the following error in case of msssql.
Connection query details:
params1 = urllib.parse.quote_plus("driver={ODBC Driver 17 for SQL Server};server=server;database=Kepler;Uid=uid;Pwd=password;Encrypt=yes;")
engine2 = 'mssql+pyodbc:///?odbc_connect={}'.format(params1)
Error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near ')'. (102) (SQLExecDirectW)")
[SQL: SELECT COUNT(*) FROM (select * from cashflow_data as foo)]
Minimal code is as follows:
import modin.experimental.pandas as pd
query = f'''select * from cashflow_data'''
file_data = pd.read_sql(sql = query, con=engine2,max_sessions = 10)
y = datetime.datetime.now() - x
Dataset example:
instu_id | cashflow_amount | currency_code | cf_type | data_date | import_source | entity | maturity_date |
---|---|---|---|---|---|---|---|
6.03675E+11 | 7500 | KWD | P | 30-Sep-19 | MANUAL | RFOL | 1-May-20 |
6.03468E+11 | 635.143 | KWD | P | 30-Sep-19 | MANUAL | RFOL | 30-Sep-19 |
6.03474E+11 | 20000 | KWD | P | 30-Sep-19 | MANUAL | RFOL | 31-Oct-19 |
6.03E+11 | 5149 | KWD | P | 30-Sep-19 | MANUAL | RFOL | 18-Feb-20 |
6.03511E+11 | 16635 | KWD | P | 30-Sep-19 | MANUAL | RFOL | 30-Oct-19 |
@devin-petersohn : Any way to fix it
Issue Analytics
- State:
- Created 4 years ago
- Comments:25 (11 by maintainers)
Top Results From Across the Web
modin incorrect syntax error on read_sql with oracle
Using modin's implementation of read_sql, I am getting a syntax error. It seems to be due to the aliasing of the count query...
Read more >COUNT field incorrect or syntax error-sql-server
Resolved this. A bit of hack, but works. I first changed it to using pyodbc instead of sqlalchemy. so my query string became:...
Read more >Read SQL Server error logs using the xp_readerrorlog ...
Syntax for xp_ReadErrorLog command · LogNumber: It is the log number of the error log. · LogType: We can use this command to...
Read more >pandas.read_sql — pandas 1.5.2 documentation
Read SQL query or database table into a DataFrame. This function is a convenience wrapper around read_sql_table and read_sql_query (for backward compatibility).
Read more >"Incorrect syntax" error when you add a subscription by using ...
Fixes incorrect syntax error when you add a subscription by using the "sp_addpullsubscription_agent" stored procedure in SQL Server.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @SudharsanRama, we are planning on getting this fix out for all databases in the next release.
As a temporary workaround, you can pass a SQLAlchemy connection to the
pd.read_sql
command. It will not run in parallel, but it should work.Hi @devin-petersohn and @mvashishtha.
Has this been fully addressed? I think there’s a flaw w/ your implementation for SQL Server when the SQL query includes an ORDER BY clause. T-SQL doesn’t permit ORDER BY clauses in subqueries.
If I create a SQLAlchemy engine and pass it to the read_sql function, Modin reverts to pandas to extract the data from the database.
But if I pass a connection string to use the ModinDatabaseConnection class, then the row_count_query method breaks because of the ORDER BY clause contained w/in the original SQL query.
Now if I remove the ORDER BY clause in the SQL text and pass a connection string, then it seems that the read_sql function just hangs.
I don’t experience this same behavior if I use something like polars’ read_sql method. Polars uses connectorx as it’s database engine, not SQLAlchemy. The downside is that connectorx doesn’t support Snowflake
Thoughts?