zoukankan      html  css  js  c++  java
  • 2021.10 db2转换openGauss个人工作总结及心得

    2021.10 个人工作总结及心得

    1.抛出自定义异常,事务回滚

    org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction;
    nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    

    问题场景: 在同一个事务中,抛出自定义异常,该异常继承RuntimeExcpetion,且使用try catch无效,持久层使用JPA

    2.定义数据库表字段,不应该使用其他数据库关键字

    • 创建表结构使用关键字,更换数据库时会造成麻烦
    • 不应使用如:order、desc、explain等关键字
    • 更多关键字规避应该参考当前使用数据库规范

    3.db2与pgsql常见表结构信息查询对照

    • db2查询某schemal下所有表名
    select tabname from SYSCAT.TABLES where TABSCHEMA ='当前表空间名称'
    
    • db2查询某表下所有字段
    select * from SYSCAT.COLUMNS where TABSCHEMA ='当前表空间'
    and TABNAME = '当前表名称'
    order by SYSCAT.COLUMNS.COLNO
    
    • db2查询某表及该表的记录数
    select tabname,card from syscat.tables where tabschema ='当前表空间'
    --tabname: 表名
    --card: 总行数
    --tabschema: 模式、架构
    
    • 查询postgresql下所有表名
    select tablename from pg_tables where schemaname = '当前表空间'
    
    • 查询postgresql某表下所有字段
    select * from information_schema.columns c 
    where table_schema = '当前表空间' and table_name  = '当前表名'
    order by ordinal_position 
    
    • 查询postgresql某表及该表的记录数
    select schemaname,relname ,n_live_tup 
    from pg_catalog.pg_stat_user_tables 
    where schemaname = '模式'
    order by n_live_tup desc; 
    --schemaname: 模式
    --relname : 表名称
    --n_live_tup : 总行数
    

    4.with子句查询

    • 在db2中使用with,涉及递归,使用 with temp(select * from a,temp where a.id = temp.id) [比较复杂!!]
    • 在pgsql中使用with子句,如涉及递归,应使用 with recursive temp(xxx)

    5.涉及外键的表清空

    • 不涉及外键的表,可以使用 truncate table 表名称 进行清空
    • db2中清空表结构,使用 truncate table tableName immediate; 清空
    • 涉及外键的表清空,使用 truncate table tableName cascade; 级联清空

    6.db2与pgsql索引查询对照

    --db2查询索引
    select * from syscat.indexes where tabname = '表名'
    
    -- pgsql查看索引
    select * from pg_catalog.pg_indexes where tablename = 'tableName';
    

    7.关于varchar字段类型

    DB2数据库版本 ,数据库编码UTF-8环境下:
    1个中文字符在表结构中占3个varchar字符,1个字符占一个varchar字符,
    1个数据占一个varchar字符,varchar(20)最多可以存放6个中文字符,再加2个字母或数据

    8.db2转换pgsql其他备注

    1.with 临时表语法支持
    2.fetch first 10 rows only 支持
    3.探测语句
    db2: select 1 from sysibm.sysdummy1
    pgsql: select 1

    4.时间函数转换
    current date 修改为 current_date
    hour(a.fb_time) >=8 修改为 extract(hour from a.fb_time) >= 8

    5.pgsql 不支持空串,空即null
    6.db2截取大字段,dbms_lob.substr(field), pagsql不支持
    7.db2中clob类型对应pgsql text类型,blob类型队形bytea类型
    8.JPQL中in查询 最好写成 in : param,或者 in(:param), 不加括号保留一个空格

  • 相关阅读:
    02 createJS中关于图片优化的问题(推荐一个图片优化的网站)
    01 createJS代码作用域
    文件读取一些payload
    SQL注入笔记-updatexml与extractvalue
    四位数六位数字典生成
    XShell上传文件到Linux服务器上
    centos彻底删除文件夹创建文件
    2020.6.18 时间记录 总学习5.15
    2020.6.14 时间记录
    五种IT职位的介绍
  • 原文地址:https://www.cnblogs.com/ixan/p/15487963.html
Copyright © 2011-2022 走看看