I have been asking this myself for a while now, I generally do enjoy writing SQL, but I also get the feeling that it's not suitable for building applications.<p>So why is there no "functional" query language? Something like Haskell, but for databases. You would get the benefits of a declarative model, composeability and type-safety.<p>I am currently using sqlx[1] and it's great in terms of type-safety, but you can't compose queries. I don't like to use ORM's, they are usually good for simple things, but hard things are impossible and you have to use/understand SQL anyways.<p>[1] https://github.com/launchbadge/sqlx
What about <a href="https://docs.datomic.com/on-prem/query/query.html" rel="nofollow">https://docs.datomic.com/on-prem/query/query.html</a><p>and more generally<p><a href="https://en.wikipedia.org/wiki/Datalog" rel="nofollow">https://en.wikipedia.org/wiki/Datalog</a> ?<p>(Around 2010 I was frustrated with the state of OWL/RDF/SPARQL and all that and was curious about Datalog and found it was truly obscure and hard to find good reading about, interest in Datalog has exploded since then.)<p>Note SQL has subqueries and in some sense is "composable", there are even some advanced features like<p><a href="https://www.postgresql.org/docs/current/queries-with.html" rel="nofollow">https://www.postgresql.org/docs/current/queries-with.html</a><p>it is ugly as hell and has problems with consistently using unique names (like the "hygenic macro" problem) but you can write crazy-complicated queries in SQL.
You might be interested in Q, which is the query language for kdb:<p>[1] <a href="https://en.wikipedia.org/wiki/Q_(programming_language_from_Kx_Systems)" rel="nofollow">https://en.wikipedia.org/wiki/Q_(programming_language_from_K...</a>
It may be great to have a functional language which will write you an SQL query, but I have a hard time to image how else are you going to use a language for describing immutable data structures to edit mutable things.<p>Maybe you will be interested in Erlang as a functional way to manage something as mutable as network stream.<p>Maybe you need to learn about array programming languages (APL, J, K). They say about SQL as "to suck data throw a thin pipe" after APL experience.<p>Maybe you will like dealing with pure AST (I'm talking about Lisp) with no databases at all.
Based on your comment about composability, I'm assuming that's what you actually meant by "functional"? Perhaps you want maps & folds over queries?