Postgres ENUM data type or CHECK CONSTRAINT?

前端 未结 6 1668
失恋的感觉
失恋的感觉 2021-01-29 23:24

I have been migrating a MySQL db to Pg (9.1), and have been emulating MySQL ENUM data types by creating a new data type in Pg, and then using that as the column definition. My q

6条回答
  •  野性不改
    2021-01-30 00:16

    One of the big disadvantages of Foreign keys vs Check constraints is that any reporting or UI displays will have to perform a join to resolve the id to the text.

    In a small system this is not a big deal but if you are working on a HR or similar system with very many small lookup tables then this can be a very big deal with lots of joins taking place just to get the text.

    My recommendation would be that if the values are few and rarely changing, then use a constraint on a text field otherwise use a lookup table against an integer id field.

提交回复
热议问题