Skip to content

Commit 68ff951

Browse files
Always commit when executing DDL
This fixes a problem seen when preprocessing SystmOne data on the CPFT server. If a 'crate_pk' column was added to a table and an index created on this column, SQL Server would report that this column didn't exist
1 parent 18c6fdc commit 68ff951

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

cardinal_pythonlib/sqlalchemy/schema.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,18 @@ def execute_ddl(
417417
if sql:
418418
ddl = DDL(sql)
419419
with engine.connect() as connection:
420-
# DDL doesn't need a COMMIT.
421420
connection.execute(ddl)
421+
# DDL may need a commit for some dialects:
422+
#
423+
# Generic (but generic may not be useful)
424+
# https://stackoverflow.com/questions/730621/do-ddl-statements-always-give-you-an-implicit-commit-or-can-you-get-an-implicit
425+
# Oracle - autocommitted?
426+
# https://docs.oracle.com/cd/A97335_02/apps.102/a83723/keyprog6.htm
427+
# but not Postgres?
428+
# https://dba.stackexchange.com/questions/340916/why-must-i-commit-after-the-alter-table-ddl-to-make-changes-visible
429+
# and in SQL Server they are "batched" so not entirely autocommitted
430+
# https://www.mssqltips.com/sqlservertip/4591/ddl-commands-in-transactions-in-sql-server-versus-oracle/
431+
connection.commit()
422432

423433

424434
# =============================================================================

0 commit comments

Comments
 (0)