4 ms·
No. This is binding your data structure to a single access pattern. You can get all the reviews for a restaurant. Now what if you want all the reviews left by a
by liontwist 2y ago
No. This is binding your data structure to a single access pattern. You can get all the reviews for a restaurant. Now what if you want all the reviews left by a particular user?
I invite you to read the original relational database paper which addresses this exact use case: A Relational Model of Data for Large Shared Data Banks
- LudwigNagasena 2y agoStoring such data structure would be binding to a single access pattern, I agree. But a query to retrieve such structure is simply convoluted for no reason to the point of many people resorting to hacks like json_agg.
- liontwist 2y agoMake a SQL view for the tree and a function in the client application which can read a tree in its linear projected form.
- LudwigNagasena 2y agoIf SQL were flexible, I wouldn’t need to create a whole view for a single query.
- liontwist 2y agoYou’re telling me there are two presentations of reviews (by restaurant and by user) but it’s too much work to define a query for those two views. I guess your app can just not support that feature and keep the tree? What do you want to hear?