4 ms·
This is a quip that misses the parent's point. SQL isn't very composable, because its syntax requires infix notation, position-dependent phrases, separators, an
by niftich 9y ago
This is a quip that misses the parent's point. SQL isn't very composable, because its syntax requires infix notation, position-dependent phrases, separators, and the like. The abstract syntax tree of SQL is much more valuable than its syntax, which is essentially just a bad English serialization that resembles a natural language sentence.
A DSL which manipulates queries and then produces syntactically valid SQL is tremendously valuable.
- ako 9y agoSQL 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.
- tkyjonathan 9y agoBare in mind that SQL was designed to allow non-technical business users to use it. In most offices, a vetern business user or BI person will know how to use SQL. So SQL is a DSL for relational deconstructing of data models that is conceptually simple enough for people to grasp. Templating can absolutely save time and boilerplate, but adding a DSL over a DSL in the form or ORM may well be the problem.