美文网首页PostgreSQLPostgreSQL
Oracle vs PostgreSQL,研发注意事项(6)-

Oracle vs PostgreSQL,研发注意事项(6)-

作者: EthanHe | 来源:发表于2018-09-10 18:46 被阅读7次

    本节介绍了Oracle和PG在事务处理上面的部分不同点。
    Oracle
    Oracle数据库,在同一个事务中的多个语句,如某个语句执行出错,该语句不影响其他语句的执行,如事务提交,则执行成功语句会持久化到DB中。
    测试脚本:

    TEST-orcl@server4>drop table tbl3;
    
    Table dropped.
    
    TEST-orcl@server4>create table tbl3(var varchar(2),fixed char(2));
    
    Table created.
    
    TEST-orcl@server4>
    TEST-orcl@server4>insert into tbl3 values('1','1');
    
    1 row created.
    
    TEST-orcl@server4>insert into tbl3 values('2','2');
    
    1 row created.
    
    TEST-orcl@server4>insert into tbl3 values('测试x3','测试x3');
    insert into tbl3 values('测试x3','测试x3')
                            *
    ERROR at line 1:
    ORA-12899: value too large for column "TEST"."TBL3"."VAR" (actual: 6, maximum:
    2)
    
    
    TEST-orcl@server4>insert into tbl3 values('4','4');
    
    1 row created.
    
    TEST-orcl@server4>
    TEST-orcl@server4>commit;
    
    Commit complete.
    
    TEST-orcl@server4>
    TEST-orcl@server4>select * from tbl3;
    
    VA FI
    -- --
    1  1
    2  2
    4  4
    
    TEST-orcl@server4>
    

    PG
    PG数据库,在同一个事务中的多个语句,如某个SQL语句执行出错,则就算在其后执行commit,事务也会回滚。如在该出错语句之后执行其他DML语句,则会报错。

    testdb=# drop table if exists tbl3;
     tbl3;DROP TABLE
    testdb=# create table tbl3(var varchar(2),fixed char(2));
    CREATE TABLE
    testdb=# 
    testdb=# begin;
    BEGIN
    testdb=# 
    testdb=# insert into tbl3 values('1','1');
    INSERT 0 1
    testdb=# insert into tbl3 values('2','2');
    INSERT 0 1
    testdb=# insert into tbl3 values('测试3','测试3');
    ERROR:  value too long for type character varying(2)
    testdb=# insert into tbl3 values('4','4');
    ERROR:  current transaction is aborted, commands ignored until end of transaction block
    testdb=# 
    testdb=# commit;
    ROLLBACK
    testdb=# 
    testdb=# select * from tbl3;
     var | fixed 
    -----+-------
    (0 rows)
    

    相关文章

      网友评论

        本文标题:Oracle vs PostgreSQL,研发注意事项(6)-

        本文链接:https://www.haomeiwen.com/subject/cgcegftx.html