3 ms·
Super cool, but it seems like this is throwing technology at a problem that could be solved in a much simpler way. Since you will rarely (if ever?) be looking
by sync 13y ago
Super cool, but it seems like this is throwing technology at a problem that could be solved in a much simpler way.
Since you will rarely (if ever?) be looking up a single question in a survey, storing the whole set as a JSON array-of-arrays makes much more sense. Then you can look up the set of questions with a dead-simple SELECT.
- tta 13y agoI'm not familiar with JSON in Postgres, but thanks for the tip. Definitely something we can look into.
- joevandyk 13y agoI'm assuming you'd want to link an answer to a particular question. And have referential integrity. JSON is great if you don't need foreign keys to catch integrity problems.
- Erwin 13y agoI agree that recursive queries overcomplicate things greatly. Store the whole thing as a semi-typed JSON document, consider adding a thin caching layer to avoid re-parsing it on every hit (perhaps with some kind of sticky load balancing if you are running multiple processes -- I don't know how the app setup he uses work). Plus, depending on who your users, the amount of options you'll want your questions/answers to have will steadily increase, making it more suitable to a semi-typed JSON tree (I say that based on a decade's commercial experience in this field -- and at the very beginning I was doing it via Perl CGI scripts). Plus, if you really really wanted, with PG 9.3+ you an actually do queries within the JSON. One tip: make sure everything has a system-generated unique ID.