Oracle PG data type 数据类型转化

(updated 2023-05-08) For those of you out there working with PostgreSQL in a professional way, migrating from Oracle to PostgreSQL might be one of the most beloved tasks available. One of the first things most people will notice, however, is that the datatypes available in Oracle might not be quite the same in PostgreSQL. This blog will try to shed some light on the differences between Oracle and PostgreSQL datatypes. It provides you with a list of how they compare.
Table of Contents

Datatypes in Oracle and PostgreSQL

While there are many similarities between Oracle and PostgreSQL, there are a couple of differences which are quite noteworthy. The first thing many people might notice is: PostgreSQL has many more data types than Oracle. As of version 10.0 an empty PostgreSQL database will expose the staggering number of 92 data types. Of course not all of them are useful, and many of them are purely used for internal purposes.

Still: At the end of the day there are just more data types which can be used by applications.

Let's take a look and see which types can be matched. The following table contains a lot of potential options:

Oracle type Possible PostgreSQL types
CHAR char, , varchar``text
NCHAR char, , varchar``text
VARCHAR char, , varchar``text
VARCHAR2 char, , , varchar``text``json
NVARCHAR2 char, , varchar``text
CLOB char, , , varchar``text``json
LONG char, , varchar``text
RAW uuid, bytea
BLOB bytea
BFILE bytea (read-only)
LONG RAW bytea
NUMBER numeric, , , , , float4``float8``char``varchar``text
NUMBER(n,m) with m<=0 numeric, , , , , , , , , float4``float8``int2``int4``int8``boolean``char``varchar``text
FLOAT numeric, , , , , float4``float8``char``varchar``text
BINARY_FLOAT numeric, ``float4``, ``float8``, ``char``, ``varchar``, ``text
BINARY_DOUBLE numeric, , , , , float4``float8``char``varchar``text
DATE date, , , , , timestamp``timestamptz``char``varchar``text
TIMESTAMP date, , , , , timestamp``timestamptz``char``varchar``text
TIMESTAMP WITH TIME ZONE date, , , , , timestamp``timestamptz``char``varchar``text
TIMESTAMP WITH LOCAL TIME ZONE date, , , , , timestamp``timestamptz``char``varchar``text
INTERVAL YEAR TO MONTH interval, , , char``varchar``text
INTERVAL DAY TO SECOND interval, , , char``varchar``text
XMLTYPE xml
MDSYS.SDO_GEOMETRY geometry

As you can see, all types can always be represented as and as . However, this is of course not desirable. What's more, in Oracle there is no such thing as an . Everything is represented as . For example: In Oracle you might see number (5, 0). The way to map this is to use integer or bigint on the PostgreSQL side. In general, "CPU data types" such as and are much faster than .text``varchar``integer``number``integer``bigint``numeric

A second important thing is : On the PostgreSQL side it can easily be mapped to or . A small detail is that in Oracle, can be the number of bytes or the number of characters. Consider the following example: vs. . You don't have to think twice about what to do on the PostgreSQL side, because in Postgres we are always talking about "characters".varchar2``varchar``text``varchar2``VARCHAR2(20 BYTE)``VARCHAR2(10 CHAR)

Oracle → PostgreSQL: Automatic conversion

Of course there is no need to do most of the work by hand. The CYBERTEC Migrator automatically maps data types for you. The Migrator also helps with indexes and constraints, and is constantly updated with robust new features to make your migration as easy and as fast as possible. You can get a FREE download of the Standard edition to try it out. The Migrator is also available on the SUSE Marketplace, which features products that are particularly robust and compatible with SUSE and Rancher software.

相关推荐
江湖中的阿龙1 天前
Oracle 紧急安全警报:Java 9.1 分漏洞 CVE-2026-91403,撤销对 eMudhra 风险证书的信任
java·安全·oracle
杨云龙UP1 天前
Oracle 同义词(SYNONYM)详解及 Toad for Oracle SQL 智能补全配置实战
运维·数据库·sql·oracle·同义词·toad·toad for oracle
loulanyue_1 天前
AI Agent记忆从不是向量库:Oracle拆解读写分离与记忆晋升门,终结无脑存聊天的伪智能——读Wojtek Pluta演讲
数据库·人工智能·oracle
我要见SA姐13 天前
GitHub Actions 自动化:5 个真实运维提效案例
运维·数据库·机器学习·oracle·回归
betazhou3 天前
MySQL Oracle官方备份工具
数据库·mysql·oracle
木木_Q4057733493 天前
Oracle 增量同步配置指南:只搬变了的数据,不重复也不漏数
数据库·oracle·数据同步·数据库同步·增量同步
测试盐4 天前
oracle数据库卡顿排查
数据库·oracle
AI小百科4 天前
向量数据库:AI 的「记忆仓库」是怎么工作的
数据库·人工智能·oracle
画中有画4 天前
在自动化脚本中操作本地数据库
数据库·oracle·自动化
LMT流氓兔4 天前
第五单元——第十六课:给书店助手加上网页界面
java·开发语言·jvm·人工智能·oracle·langchain·1024程序员节