本节介绍TDSQL PG数据库在Oracle兼容方面的特性。
TDSQL PG数据库基本兼容了Oracle的数据类型、SQL功能、数据库对象(如:同义词、包)。在PL(过程化语言)方面也做了很多细致兼容工作,用户应用迁移基本不需要改动业务代码。
TDSQL PG对如下功能做了兼容:
- SQL基本元素
- 伪列
- 操作符
- SQL表达式
- 条件
- 常见SQL语法
- PL/SQL
- 系统函数
- 系统视图
- 系统包
- Oracle兼容性配置参数
使用Oracle兼容模式
TDSQL PG内核引擎支持Oracle 和PostgreSQL 两种SQL兼容模式。
在创建数据库的时候使用sql mode``<sql_mode> 即可指定创建数据库的兼容模式,其中<sql_mode>可选oracle或postgresql。不指定默认是PostgreSQL 兼容模式。SQL 兼容模式涉及底层底层存储和 SQL 行为,指定后无法改变。
示例:
tdsql=# create database ora sql mode oracle;
CREATE DATABASE
tdsql=# \l
List of databases
Name | Owner | Encoding | Sqlmode | Collate | Ctype | Access privileges
---------------+-------+----------+----------+------------+------------+-------------------
ora | tbase | UTF8 | oracle | zh_CN.utf8 | zh_CN.utf8 |
postgres | tbase | UTF8 | postgres | zh_CN.utf8 | zh_CN.utf8 |
tbase_db | tbase | UTF8 | postgres | zh_CN.utf8 | zh_CN.utf8 |
tdsql | tbase | UTF8 | postgres | zh_CN.utf8 | zh_CN.utf8 |
template0 | tbase | UTF8 | postgres | zh_CN.utf8 | zh_CN.utf8 | =c/tbase +
| | | | | | tbase=CTc/tbase
template0_ora | tbase | UTF8 | oracle | zh_CN.utf8 | zh_CN.utf8 | =c/tbase +
| | | | | | tbase=CTc/tbase
template1 | tbase | UTF8 | postgres | zh_CN.utf8 | zh_CN.utf8 | =c/tbase +
| | | | | | tbase=CTc/tbase
template1_ora | tbase | UTF8 | oracle | zh_CN.utf8 | zh_CN.utf8 | =c/tbase +
| | | | | | tbase=CTc/tbase
user1 | user1 | UTF8 | postgres | zh_CN.utf8 | zh_CN.utf8 |
(9 rows)
可以看到 ora 数据库的 Sqlmode 列显示 oracle,即表示 ora 数据库为 Oracle 兼容模式。
而 tdsql 数据库的 Sqlmode 列显示 postgres,即表示 tdsql 数据库为 PostgreSQL 兼容模式。