Limits on PostgreSQL schema changes inside transactions?

后端 未结 5 1258
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 09:59

My database background is with Oracle, so I was surprised to discover that Postgres includes schema changes in transactions - if you begin one, create a table and then rollb

5条回答
  •  迷失自我
    2021-01-11 10:37

    As of version 9.1 of PosgreSQL, it appears that schema create statements are indeed transactional.

    select * from pg_namespace where nspname = 'foo';
     nspname | nspowner | nspacl 
    ---------+----------+--------
    (0 rows)
    
    begin;
    create schema foo;
    rollback;
    
    select * from pg_namespace where nspname = 'foo';
     nspname | nspowner | nspacl 
    ---------+----------+--------
    (0 rows)
    
    begin;
    create schema foo;
    commit;
    
    select * from pg_namespace where nspname = 'foo';
     nspname | nspowner | nspacl 
    ---------+----------+--------
     foo     |       10 | NULL
    (1 row)
    

提交回复
热议问题