数据库
首页 > 数据库> > 2021.10 db2转换openGauss个人工作总结及心得

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.定义数据库表字段,不应该使用其他数据库关键字

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

select tabname from SYSCAT.TABLES where TABSCHEMA ='当前表空间名称'
select * from SYSCAT.COLUMNS where TABSCHEMA ='当前表空间'
and TABNAME = '当前表名称'
order by SYSCAT.COLUMNS.COLNO
select tabname,card from syscat.tables where tabschema ='当前表空间'
--tabname: 表名
--card: 总行数
--tabschema: 模式、架构
select tablename from pg_tables where schemaname = '当前表空间'
select * from information_schema.columns c 
where table_schema = '当前表空间' and table_name  = '当前表名'
order by ordinal_position 
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子句查询

5.涉及外键的表清空

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), 不加括号保留一个空格

标签:2021.10,--,查询,pgsql,openGauss,db2,where,select
来源: https://www.cnblogs.com/ixan/p/15487963.html