I'm trying to red and execute a SQL file in Python using sqlalchemy. Should be simple, right?
conn=sqlalchemy.create_engine('mssql+pyodbc://' + DSN).connect()
query = open('../toy_example.sql',encoding="utf-8").read()
trans = conn.begin()
conn.execute(query)
trans.commit()
I get this error
ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near '\ufeff'. (102) (SQLExecDirectW)")
[SQL: drop table temp;
With t0 as (select 1+1)
select * into temp from t0]
Why am I getting this error? I'm not sure if this is a file encoding error or a SQLAlchemy error. Ideally, this should be simple.
EDIT:
This code works fine, assuming the table temp exists:
conn=sqlalchemy.create_engine('mssql+pyodbc://' + DSN).connect()
query = "drop table temp; With t0 as (select 1+1 t) select * into temp from t0"
trans = conn.begin()
conn.execute(query)
trans.commit()
EDIT 2:
For reference, here is a link to the file toy_example.sql.
http://s000.tinyupload.com/index.php?file_id=62746453331292257227