5 ms·
Yes, i am talking about asking pg to output json. This is mostly to make sure I get the structure I want with nested arrays etc, it is unnecessary with a singl
by uptime 8y ago
Yes, i am talking about asking pg to output json. This is mostly to make sure I get the structure I want with nested arrays etc, it is unnecessary with a single level query.
ORMs are not evil, but I like doing my queries in sql (and using pg functions). In the past I’ve seen the separate queries that an ORM would send to the db to build the data objects I wanted at the app level and I found it more comfortable to pound on queries in sql, then make a view so the app only needs to do simple selects. It was easier for me to maintain. I’m not saying it was the ORMs fault, but I liked having the ability to keep tables simple, make joined structures in views, then dump json out from there. With CTEs it is easy to nest arrays within parents etc. Then with PG we can materialize the view for data that doesn’t change frequently.
As horrible as that all sounds, hasura is the first layer that makes me want to try app directed queries, schema migrations etc. I got tempted by django way back but missed that train.
- e12e 8y agoAh, I think I see now. So it's not that you strongly prefer ctes to joins when manually writing sql and creating regular (or materialized) views - but that when writing views that output json, ctes are a natural fit?