How to store days of the week of opening in the database

I have a group of flags where the user selects some of the weekdays (store opening days). How to save selected days? Should I save something like 0111111 (zero means closed on Sunday) in one field and split the result when reading data? Or create a field for each day and keep 0 or 1 on each (weird)?

+4
source share
2 answers

The first approach saves space, the second improves performance when retrieving data, especially if you need to filter by a separate weekday. He also makes requests that manipulate weekdays more clear. You must decide what is more important to you based on the application logic.

In general, I would use the solution in the field.

+7
source

It completely depends on what you are going to do with this data as soon as you receive it. By and large, if these seven factoids (weekdays, when the store is open) are one fact, they will be considered as one fact, and you will never have to disassemble and individually process one of the โ€œfactoidsโ€ inside the line, then it can and, possibly, should be stored as one piece of data.

But, if you need to consider this information as seven different pieces of data, you better write it as seven different pieces of data (i.e. seven different columns).

Again, there is a lot of โ€œbehindโ€ behind it. Another way to think about this is to look at how you will use the data, and try to structure the repository to simplify your processes (i.e. do you want to always parse the string "1010101" for the elements you want?)

0
source

Source: https://habr.com/ru/post/1308253/


All Articles