Kasprovv
Kasprovv

Reputation: 13

SQL Alchemy python DELETE records, strange schema

I have problem with clearing the table (deleting records).

The table have rep schema like that: PROD\USER.TableName

My code looks like that:

params = urllib.parse.quote_plus("DRIVER={SQL 
SERVER};SERVER=XXXXX;DATABASE=DBNAME;")
engine = sqlalchemy.create_engine("mssql+pyodbc:///?odbc_connect=%s" % 
params)

c=engine.connect()
sql=("DELETE * FROM PROD\\USER.TableName")
result=c.execute(sql)

What am I doing wrong and how can I makes this work (I cannot change the schema of DB).

ERROR: Incorrect syntax near *

Upvotes: 1

Views: 483

Answers (1)

Mureinik
Mureinik

Reputation: 310983

delete doesn't take a column list (unless you're using top). Just lose the *. Additionally, it's probably a good idea to escape the schema name:

sql=("DELETE FROM [PROD\\USER].TableName")

Upvotes: 3

Related Questions