1 year ago
#381566
BigBlueMonster
row_number query in Dask with SQLAlchemy 1.3
I am trying to get SQLAlchemy to create the following standard SQL query:
SELECT ROW_NUMBER() OVER (ORDER BY(select 0)) AS row_num, User_Id FROM my_table
Using the following code:
from sqlalchemy import create_engine, Table, func, Column, MetaData
from sqlalchemy.sql import select
/* engine details */
metadata = MetaData()
t = Table('my_table', metadata, Column('User_Id'))
sql_query = select([func.row_number().over(order_by=select([0])).label('row_num'), t])
/* run sql query code */
However I get this error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near ','. (102) (SQLExecDirectW)")
[SQL: SELECT row_number() OVER (ORDER BY (SELECT 0)) AS row_num, my_table.[User_Id]
FROM (SELECT 0), my_table]
I assume it is because of the FROM (SELECT 0), my_table
part of the query. How can I remove (SELECT 0)
from the FROM statement in my sql_query
?
python
sqlalchemy
dask
0 Answers
Your Answer