Postgresql枚举有什么优点和缺点? [英] Postgresql enum what are the advantages and disadvantages?

查看:652
本文介绍了Postgresql枚举有什么优点和缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里工作,我们使用一个postgres数据库(8.3很快迁移到8.4)。目前在数据库中使用枚举有一个小小的争论。个人我不喜欢db枚举类型。除此之外,它还将应用程序逻辑放在数据库中,并为代码和数据之间的不匹配创建了可能性。

Where I work we use a postgres database (8.3 soon to migrate to 8.4). There is a small debate currently on the use of enums in the database. Personally I do not like the db enum type. Among other things it puts application logic in the database and creates a posibility for a mismatch between code and data.

我想知道postgres枚举(除了readablity)的优点究竟是什么和缺点是什么?

I was wondering what exactly are the advantages of postgres enums (besides readablity) and what are the disadvatages?

推荐答案

枚举的优点是:


  • 性能更好。您可以只显示您从核心表中获取的内容,而不是具有将代码转换为值的单独查找表,或具有将代码转换为值的应用程序逻辑。这在数据仓库应用程序中特别有用。

  • 临时SQL更容易写入

缺点是:


  • 将显示值编码到数据库ddl是坏的形式。如果您将应用代码中的枚举值转换为不同的显示值,那么您就失去了使用枚举的许多优势。

  • 添加值需要DDL更改

  • 使语言本地化困难

  • 数据库可移植性降低

  • Encoding display values into your database ddl is bad form. If you translate the enum value into a different display value in your app code, then you lost a lot of the advantages of using enums.
  • Adding values requires DDL changes
  • Makes language localization difficult
  • Database portability is decreased

这篇关于Postgresql枚举有什么优点和缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆