question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A way to run non-transactional DDL commands / PG requires autocommit to modify a type ?!

See original GitHub issue

Migrated issue, originally created by Wichert Akkerman (@wichert)

Unfortunately not all DDL commands for PostgreSQL can be used in a transaction. I ran into this when trying to add a new value to an enum:

db=# BEGIN;
BEGIN
db=# ALTER TYPE article_type ADD VALUE 'unknown';
ERROR:  ALTER TYPE ... ADD cannot run inside a transaction block

I’m not sure what the best way to handle this is in alembic currently. Perhaps do op.execute('COMMIT') manually? Perhaps alembic needs an in-between-commit operation for this.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sqlalchemy-botcommented, Nov 27, 2018

Wichert Akkerman (@wichert) wrote:

Looks like psycopg2 doesn’t do that here for some reason. This code ran without problems:

op.execute('COMMIT')  # See https://bitbucket.org/zzzeek/alembic/issue/123
op.execute('ALTER TYPE article_type ADD VALUE \'unknown\'')
0reactions
sqla-testercommented, Sep 17, 2019

Mike Bayer has proposed a fix for this issue in the master branch:

Add autocommit_block https://gerrit.sqlalchemy.org/1463

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL statements That Cause an Implicit Commit - MariaDB
List of statements which implicitly commit the current transaction. ... As a rule of thumb, such statements are DDL statements. The same statements...
Read more >
13.3.1 START TRANSACTION, COMMIT, and ROLLBACK ...
By default, MySQL runs with autocommit mode enabled. ... SELECT @A:=SUM(salary) FROM table1 WHERE type=1; UPDATE table2 SET summary=@A WHERE type=1; COMMIT;.
Read more >
Non-transactional data access and the auto-commit mode
The autocommit mode is useful for ad hoc execution of SQL. Imagine that you connect to your database with an SQL console and...
Read more >
why commit is not required for DDL Commands — oracle-tech
DDL is auto commit and you need not to issue commit statement as it affects on structure or meta data in the database...
Read more >
Non-Transactional DML Statements - PingCAP Docs
Usually, memory-consuming transactions need to be split into multiple SQL statements to bypass the transaction size limit. Non-transactional DML statements ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found