Is select ... into
not something we're able to do in SQLAlchemy?
The following is a minimal example of something I'm trying to do - and it isn't adding a table to my d/b as expected.
driver = '{ODBC Driver 17 for SQL Server}'
server = xxxxxxxxxxxxxxxxxxxxxxxxx
database = xxxxxxxxxxxxxxxxxxxxxxxxx
authentication = 'ActiveDirectoryInteractive'
username = xxxxxxxxxxxxxxxxxxxxxxxxx
conn = urllib.parse.quote_plus(
'DRIVER=' + driver +
';SERVER=' + server +
';DATABASE=' + database +
';UID=' + username +
';AUTHENTICATION=' + authentication + ';'
)
engine = create_engine('mssql+pyodbc:///?odbc_connect={}'.format(conn))
with engine.connect() as cx:
cx.execute(text('''
select
name
into testing.test
from core.person
'''))
It's failing silently - I'm not getting any error message. And other queries that I run are executing fine.
Are we not able to do select ... into
queries using text
in this way? If not, is there an alternative besides separate create table
and insert into
statements?
1条答案
按热度按时间qojgxg4l1#
@GordThompson's suggestion fixed this for me, swapping
engine.connect()
forengine.begin()
:The commit behaviour of the two functions differs, as described in more detail by Gord in this answer .