> Frankly, it seems like some sort of macro system is needed.

Like dynamic SQL? That has its own problems.

Rather than trying to extend SQL I think that people should stop trying to use SQL/RDBMSs for every task.

SQL was meant to be a hosted language from the get-go though, so any kind of macro-like feature was expected to be done in the host language.

Of course it's a bit painful and error prone, given SQL is a textual language, but as HoneySQL (https://github.com/seancorfield/honeysql) shows, you can represent SQL statements as data and generate them programmatically in a safe manner. I think it's compatible with https://babashka.org/ so you don't need a full Java environment to use it.