兼容性判定
公开资料依据 · 建议 PoC 复核支持度partial
严重度major
置信度medium
依据规则my.op.integer_div
怎么改
按操作数类型显式除法后 trunc,并单独处理零除
判定说明
PostgreSQL 无 MySQL DIV 运算符;整数除法、数值提升和零除行为需显式改写,建议 PoC 复核
库侧 / 应用侧路径
库侧改造
可行:显式 cast 数值类型并用 trunc(a / b),零除按源 sql_mode 处理
应用侧改造
可行:业务层使用明确的向零取整整数除法
推荐路线:case_by_case。验证建议:正负数、小数输入、超大整数、NULL、零除和 sql_mode 对照
规则样例
SELECT 7 DIV 3
SELECT amount DIV bucket_size FROM invoice
SELECT amount / bucket_size FROM invoice
参考来源
- https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html
- https://www.postgresql.org/docs/16/functions-math.html
- https://www.postgresql.org/docs/16/datatype.html
- https://www.postgresql.org/docs/16/functions.html
- https://www.postgresql.org/docs/16/sql-commands.html
- https://github.com/tobymao/sqlglot/blob/64e268a5d95cd84a87ad74ef569fc9bf356fd3fb/README.md#unsupported-errors
相关改造点
- MYSQL → postgresql 16 全部改造点
- postgresql 16 兼容性总览
- MYSQL 迁移国产库总览
- ORACLE ADD_MONTHS 函数 迁移 postgresql 16 怎么改
- ORACLE ALTER SESSION SET 会话参数 迁移 postgresql 16 怎么改
- ORACLE ANYDATA 动态类型列 迁移 postgresql 16 怎么改
- ORACLE ASCIISTR Unicode 转义函数 迁移 postgresql 16 怎么改
- ORACLE 关联数组(INDEX BY 表) 迁移 postgresql 16 怎么改
- ORACLE AT TIME ZONE 时区表达式 迁移 postgresql 16 怎么改