Euphorichuman
`nil` or empty list?
I’m managing my Postgres database with Ecto and I have come across a situation: In some of the fields for some of my records, I save empty values: For this case, it would be an empty list [].
Empty list or nil, which is better or more efficient?
Marked As Solved
eksperimental
empty list.
See this PR that was an optimization to MapSet.
https://github.com/elixir-lang/elixir/pull/5954
Also Liked
dorgan
Tangential fun fact: In Erlang, the empty list [] is internally called nil, and it has it’s own position in the erlang term ordering ![]()
benwilson512
I would first and foremost prioritize clarity, then performance here, since the difference is negligible in most cases. If you have a column that can either have a value, or no value, then use nil to mean “no value”. If you have a collection of things and that collection can be empty, then use an [].
al2o3cr
If you’ve got a JSONB column or a nullable array column, using nil is going to cause the usual SQL NULL behaviors while using [] will not.
Last Post!
al2o3cr
If you’ve got a JSONB column or a nullable array column, using nil is going to cause the usual SQL NULL behaviors while using [] will not.
Popular in Questions
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security










