类型系统:ANSI SQL(标准)与 Postgres、Oracle、DB2
Type system: ANSI SQL (standard) vs. Postgres, Oracle, DB2
这是一个非常笼统的问题,我希望找到既熟悉标准又熟悉一些数据库系统的专家。在高层次上,SQL 标准中描述的类型系统与 Postgres、Oracle 或 DB2 中实现的类型系统之间有哪些区别。
我只是在编一些东西(它是不正确的 -- 只是用来显示我感兴趣的比较类型的格式),但是例子可能是这样的:
Standard
Postgres
Oracle
INTERVAL
type
Does not exist, closest is TIME
Same as standard.
(顺便说一句,这个问题对DBA来说会更好吗?)
很少有人能够给你一个完整的清单,所以我只告诉你我所知道的,不保证完整性。我也将自己限制在我更了解的数据库中。
对数据库实施的评论描述了与标准的偏差。
SQL standard
PostgreSQL
Oracle
Comments
CHARACTER
✔
empty strings are treated as NULL
weird standard-dictated semantics; avoid
CHARACTER VARYING
✔
empty strings are treated as NULL
CHARACTER LARGE OBJECT
non-standard name text
or varchar
✔
NATIONAL CHARACTER
✔
empty strings are treated as NULL
obsolescent
NATIONAL CHARACTER VARYING
✔
empty strings are treated as NULL
obsolescent
NATIONAL CHARACTER LARGE OBJECT
non-standard name text
or varchar
empty strings are treated as NULL
obsolescent
BINARY LARGE OBJECT
non-standard name bytea
✔
NUMERIC
✔
✔
DECIMAL
✔
✔
virtually the same as NUMERIC
SMALLINT
✔
✔ (same type as NUMERIC
)
INTEGER
✔
✔ (same type as NUMERIC
)
BIGINT
✔
✔ (same type as NUMERIC
)
FLOAT
✔
✔ (same type as NUMERIC
)
REAL
✔
✔ (same type as NUMERIC
, but there is also BINARY_FLOAT
)
DOUBLE PRECISION
✔
(same type as NUMERIC
, but there is also BINARY_DOUBLE
)
BOOLEAN
✔
❌ (but allowed in PL/SQL)
DATE
✔
is really a timestamp
TIME
✔
❌
TIME WITH TIME ZONE
✔
❌
semantics unclear; avoid
TIMESTAMP
✔
✔
TIMESTAMP WITH TIME ZONE
semantics differ from the standard
✔
INTERVAL
✔
✔
ROW
composity types
object types
REF
❌
✔ (non-standard syntax)
<type> ARRAY
✔
vararray types
<type> MULTISET
❌
❌
XML
✔
non-standard name XMLTYPE
这是一个非常笼统的问题,我希望找到既熟悉标准又熟悉一些数据库系统的专家。在高层次上,SQL 标准中描述的类型系统与 Postgres、Oracle 或 DB2 中实现的类型系统之间有哪些区别。
我只是在编一些东西(它是不正确的 -- 只是用来显示我感兴趣的比较类型的格式),但是例子可能是这样的:
Standard | Postgres | Oracle |
---|---|---|
INTERVAL type |
Does not exist, closest is TIME |
Same as standard. |
(顺便说一句,这个问题对DBA来说会更好吗?)
很少有人能够给你一个完整的清单,所以我只告诉你我所知道的,不保证完整性。我也将自己限制在我更了解的数据库中。
对数据库实施的评论描述了与标准的偏差。
SQL standard | PostgreSQL | Oracle | Comments |
---|---|---|---|
CHARACTER |
✔ | empty strings are treated as NULL | weird standard-dictated semantics; avoid |
CHARACTER VARYING |
✔ | empty strings are treated as NULL | |
CHARACTER LARGE OBJECT |
non-standard name text or varchar |
✔ | |
NATIONAL CHARACTER |
✔ | empty strings are treated as NULL | obsolescent |
NATIONAL CHARACTER VARYING |
✔ | empty strings are treated as NULL | obsolescent |
NATIONAL CHARACTER LARGE OBJECT |
non-standard name text or varchar |
empty strings are treated as NULL | obsolescent |
BINARY LARGE OBJECT |
non-standard name bytea |
✔ | |
NUMERIC |
✔ | ✔ | |
DECIMAL |
✔ | ✔ | virtually the same as NUMERIC |
SMALLINT |
✔ | ✔ (same type as NUMERIC ) |
|
INTEGER |
✔ | ✔ (same type as NUMERIC ) |
|
BIGINT |
✔ | ✔ (same type as NUMERIC ) |
|
FLOAT |
✔ | ✔ (same type as NUMERIC ) |
|
REAL |
✔ | ✔ (same type as NUMERIC , but there is also BINARY_FLOAT ) |
|
DOUBLE PRECISION |
✔ | (same type as NUMERIC , but there is also BINARY_DOUBLE ) |
|
BOOLEAN |
✔ | ❌ (but allowed in PL/SQL) | |
DATE |
✔ | is really a timestamp | |
TIME |
✔ | ❌ | |
TIME WITH TIME ZONE |
✔ | ❌ | semantics unclear; avoid |
TIMESTAMP |
✔ | ✔ | |
TIMESTAMP WITH TIME ZONE |
semantics differ from the standard | ✔ | |
INTERVAL |
✔ | ✔ | |
ROW |
composity types | object types | |
REF |
❌ | ✔ (non-standard syntax) | |
<type> ARRAY |
✔ | vararray types | |
<type> MULTISET |
❌ | ❌ | |
XML |
✔ | non-standard name XMLTYPE |