哪些数据库系统支持 ENUM 数据类型,哪些不支持?
跟进这个问题:“数据库枚举 - 优点和缺点”,我想了解哪些数据库系统支持枚举数据类型,以及它们如何实现的一些详细信息(例如内部存储的内容、限制是什么、查询语法含义、索引含义等)。
对用例或优缺点的讨论应在其他问题中进行。
Following up this question: "Database enums - pros and cons", I'd like to know which database systems support enumeration data types, and a bit of detail on how they do it (e.g. what is stored internally, what are the limits, query syntax implications, indexing implications, ...).
Discussion of use cases or the pros and cons should take place in the other questions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道 MySQL 确实支持 ENUM:
SELECT enum_col+0
”访问该字段的值ENUM('0','1 ','2')
应避免使用,因为'0'
将具有整数值1
I know that MySQL does support ENUM:
SELECT enum_col+0
"ENUM('0','1','2')
should be avoided, because'0'
would have integer value1
PostgreSQL 从 8.3 开始支持 ENUM。 对于旧版本,您可以使用 :
您可以通过执行以下操作来模拟 ENUM:
您还可以使用 :
当您了解最喜欢的颜色时添加一个连接,但优点是您可以简单地添加颜色通过向颜色表添加一个条目,并不是说您不需要每次都更改架构。 您还可以向颜色添加属性,例如 HTML 代码或 RVB 值。
您还可以创建自己的类型来执行枚举,但我认为它不会比 varchar 和 CHECK 更快。
PostgreSQL supports ENUM from 8.3 onwards. For older versions, you can use :
You can simulate an ENUM by doing something like this :
You could also have :
which would have you add a join when you get to know the favorite colour, but has the advantage that you can add colours simply by adding an entry to the colour table, and not that you would not need to change the schema each time. You also could add attribute to the colour, like the HTML code, or the RVB values.
You also could create your own type which does an enum, but I don't think it would be any more faster than the varchar and the
CHECK
.Oracle 根本不支持 ENUM。
Oracle doesn't support ENUM at all.
AFAIK,IBM DB2 和 IBM Informix Dynamic Server 都不支持 ENUM 类型。
AFAIK, neither IBM DB2 nor IBM Informix Dynamic Server support ENUM types.
与 mat 所说的不同,PostgreSQL 确实支持 ENUM (从版本
8.3,最后一个):
有些函数专门用于枚举< /a>.
索引在枚举类型上工作得很好。
根据手册,实现如下:
Unlike what mat said, PostgreSQL does support ENUM (since version
8.3, the last one):
There are functions which work specifically on enums.
Indexing works fine on enum types.
According to the manual, implementation is as follows:
MSSQL 不支持 ENUM。
使用实体框架 5 时,可以使用枚举(请参阅:实体框架中的枚举支持 和 EF5 枚举类型演练),但即使这样,值也会以 int 形式存储在数据库中。
MSSQL doesn't support ENUM.
When you use Entity Framework 5, you can use enums (look at: Enumeration Support in Entity Framework and EF5 Enum Types Walkthrough), but even then the values are stored as int in the database.