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.
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 
https://www.erlang.org/doc/reference_manual/expressions.html#term-comparisons
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.








