'How to store comma-separated value in mysql table column using postman?
I would like to store comma-separated values in a column named tags.
Example:
| id | tags |
+----+-----------------+
| 1 | hot, cold |
Please suggest the best way to do this and tell me which datatype I should use for the tags (column field).
Solution 1:[1]
Even though this question is opinion based and for better answer should be posted on https://dba.stackexchange.com/ , you should never store comma separated value.
You can use your table and store the data as follows:
| id | tags
+----+-------
| 1 | hot
| 1 | cold
Or use another table only for tags and add tag_id on your existing table (there is no need for another table if you are storing only the values in the description).
I have found json datatype as an other option to store values instead of array datatype
There is json option , but you need to understand the disadvantages of json.
If your JSON has multiple fields with the same key, only one of them, the last one, will be retained. The other drawback is that MySQL doesn't support indexing JSON columns, which means that searching through your JSON documents could result in a full table scan
You can read more on JSON if you still want to go with this data type
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ergest Basha |
