A
A
Arsen Abakarov2017-03-15 19:04:49
PostgreSQL
Arsen Abakarov, 2017-03-15 19:04:49

Null in DB, good or bad?

Let's imagine that we have a table (we will speak in terms of SQL) of product catalogs.
We need to create a hierarchy of catalogs.
You can make a foreign key in the table that links the table to itself, make it null.
You can make an intermediate table, such as a many-to-many relationship, where there will be parent_id and child_id, then no nulls, but more joins ..
Another situation, one-to-one or zero-to-one relationship, again, for example, the same directory, it may have an icon, or maybe not, it can be implemented in the same table, put the icon field there, make it null possible, or do it through a separate table..
Is it generally good or bad to keep null in the database?
In general, there will be an implementation on django in conjunction with postgresql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2017-03-15
@ArsenAbakarov

NULL is fine to keep. Why is there such a fear of NULL? Tree-like structures and store - a link to the parent. This is the most normal form. But the least efficient. Django often uses MPTT (django-mptt), which adds several fields that denormalize data, but allows you to get almost any structure in one request (for example: subtree rooted in the desired, family, descendants, ancestors, tree membership, all leaves, etc. .d.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question