4 ms·
SQL is composable if you use views, just create a view for anything that you want to reuse in multiple queries.
by ako 9y ago
SQL is composable if you use views, just create a view for anything that you want to reuse in multiple queries.
- erfgh 9y agoDoesn't work because it completely screws up query optimization.
- icebraining 9y agoMaybe in some crappy RDBMSs, but not in Postgres.
- ZenoArrow 9y agoIf you encounter such an issue, there are ways around it: https://www.red-gate.com/simple-talk/sql/performance/controlling-execution-plans-with-hints/ https://www.red-gate.com/simple-talk/sql/performance/control...
- icebraining 9y agoFor that I'd need to dynamically create such views, which requires a SQL generator anyway :)
- nine_k 9y agoViews are only half the answer. Try factoring out a set of conditions and use them both in a `select` and in `update`. Also, views tend to pollute the namespace a bit: you want a set of descriptive names, per application, and possibly per application version. Schemata help here, though.