rlefevre
What about a simple table with `varchar` primary key (used as foreign keys) instead of enums?
Hi,
I am hesitating between different solutions for a (maybe not so fixed in the future) enum field in my (postgres) database and ecto schema.
I have read several posts about this, and I quite like the solution described in Using Enums in PostgreSQL with Ecto. However I just stumbled on this old postgresql mailing list post and the technique seems appealing as it is also flexible, safer at the database level and avoids joins:
Otherwise a simple table with a primary key of type ‘text’ that is
used as a foreign key in the other table, so I can change/alter the
valid values later. No join needed! Remember that PK/FK do not always
have to be of type ‘serial’.
What do you think about it? Also does anyone use this technique and can share its experience using it (with ecto) compared to other ones?
First Post!
Qqwy
Well, what will you store in this varchar column? String representations of your enums?
Then, what happens when you change the name of one of those enum fields in your application? What happens if you load a string that is none of the possible enum values in your application?
And besides this, a varchar-column takes significantly lot more space than a single TINYINT column (which, by itself, can already store more different enum values than you’d ever need)
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









