I'm trying to use SQLAlchemy in Python to execute a bulk insert in my Azure SQL database (from blob storage). The external data source is working properly and I can run the query from SQL Server Management Studio. When I try to query from python:
query = '''
BULK INSERT mytable FROM '%s.csv' WITH (DATA_SOURCE = 'blobStorage',
FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', FIRSTROW=2)
''' % report_date
insert = connection.execute(query)
the query runs without errors. Then:
sel = connection.execute("SELECT count(*) FROM mytable where DATE='%s'" % report_date)
returns the number of new rows.
(36026,)
I can select the new rows and see the data all looks correct.
However, moving back into SQL Server Management Studio, trying to select the new rows returns nothing. The new rows aren't in the table and when I restart my Python script and try to select again, the rows are gone.
Any advice would be very much appreciated.
execute()
. It'll remove the need to manually quote etc. – Ilja Everiläcnxn.commit()
, executingCOMMIT TRANSACTION
, etc. still the insert is not persisting – seriestoo2