Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider normalizing empty values to NULL when inserting into the database #754

Open
artur-intech opened this issue Mar 6, 2018 · 4 comments
Labels

Comments

@artur-intech
Copy link
Contributor

artur-intech commented Mar 6, 2018

In Rails when saving a model from a form and values are not provided by the user, an empty string is recorded to the database instead of a NULL (mixing blanks and NULLs can become confusing).

  • Unique constraint check fails if there is more than one row with empty column
@vohmar vohmar added the bug label Mar 6, 2018
@virtualfeline
Copy link
Collaborator

Do we actually have any case where missing value is acceptable ?
Also consider that NULL returns different results than an empty string in queries. Will this affect smth? Are we sure we should prefer NULL?

@artur-intech
Copy link
Contributor Author

artur-intech commented Mar 7, 2018

@virtualfeline This is the default behaviour of Rails, if by missing value you mean empty string. I bet 99% of text columns in our database are empty if no value has been provided at the application level. I don't see production data so I cannot say how many of them are empty.

Also consider that NULL returns different results than an empty string in queries

Exactly! I am sure I want to see NULL when the data is missing or unknown, since this is the point of NULL. But is it worth the effort or not, is the topic of this ticket.
If we leave it as is:

  • It makes application code more complex
  • Every time you do some string comparison (which is a lot of cases), you have to remember the fact that you need to include empty string check in addition to IS[NOT] NULL. This is error-prone. It means the data you get will be inaccurate.
    It applies to both application and database levels.

@artur-intech
Copy link
Contributor Author

Example: #746 introduced contact reuse, so if one contact has fax value of "", and another of NULL, they will not be considered identical, and therefore will not be reused.
@vohmar FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants