I have the following record and I am trying to store it in a table.
{
"properties": {
"visitor_id": "0184d099_n00mPLKQT"
},
"flags": {
"5001": true,
"5003": true
},
"audiences": [
"main_public"
],
"badges": [
"90",
"70"
]
}
I have come up with a basic table schema that can store the record but the insertion process takes some time.
____________________ _______ _______ _____________
| visitor_id | badge | flags | audience |
| ------------------ | ----- | ----- | ----------- |
| 0184d099_n00mPLKQT | 70 | 5001 | main_public |
| 0184d099_n00mPLKQT | 70 | 5003 | main_public |
| 0184d099_n00mPLKQT | 90 | 5001 | main_public |
| 0184d099_n00mPLKQT | 90 | 5003 | main_public |
|------------------- | ------| ----- | ----------- |
Another solution I thought was about a table with multiple columns, that is, a column for each badge, flags and audiences. The benefit of this solution is that I will have 1 record with all the information of the visitor instead of multiple rows. The downside is that I will have to change the table schema in case a new flag, badge or audience is not contained.
____________________ __________ _________ __________________ ___________ ___________
| visitor_id | badge_70 | badge_90| audience_main | flag_5001 | flag_5003 |
| ------------------ | ---------| ------- | ---------------- | --------- | --------- |
| 0184d099_n00mPLKQT | True | True | True | True | True |
| 0100d099_n11mAABTT | False | True | True | True | False |
|------------------- | ---------| ------- | ---------------- | --------- | --------- |
I am looking forward to reading all of you comments about what's the best solution to store this type of json record in a table.