3 ms·
The great thing about SQL is the relational model. You typically can't compose parts of SQL queries easily from the programming language calling it, but SQL que
by nicoburns 6y ago
The great thing about SQL is the relational model. You typically can't compose parts of SQL queries easily from the programming language calling it, but SQL queries themselves compose incredibly flexibly. The result of of a SELECT query is itself a "relation" that can be queried just like a table.
I do wish someone would create a compile-to-sql language that adds variables and basic conditional support. I think T-SQL (SQL Server) has a lot of this, but it's missing in the Open Source world.
- dragonwriter 6y ago> I think T-SQL (SQL Server) has a lot of this, but it's missing in the Open Source world. Every database with a procedural language based on SQL (Oracle PL/SQL, Postgres PL/pgSQL, etc.) has it, T-SQL just doesn’t segregate procedural and declarative code the way most engines do. Mostly, I think this is a negative for T-SQL, but sometimes segregation means there’s no way to do one-off procedural scripts without making and then calling a procedure; but Postgres, for example, since 9.0 has the DO statement for this use case (which supports any procedural language installed in the DB, but defaults to PL/pgSQL.)
- TheCoelacanth 6y agoI don't think SQL does compose well. Queries aren't first-class values in SQL. I can write a query that queries the result of another query, but I can't store a query and then pass that somewhere to query from.
- pmontra 6y agoMaybe the WITH statement and CTEs can help you, if I understood correctly your complaint. Check the example at the beginning of https://www.postgresql.org/docs/13/queries-with.html https://www.postgresql.org/docs/13/queries-with.html