>Frankly, it seems like some sort of macro system is needed
Views, materialized views, CTEs.
No, these are all highly coupled to the underlying data structure. Even stored procedures tend to know a bit too much.
Say I have a table with the following properties:
- It has a column that corresponds to an id
- It has a column that corresponds to a category
- It has a column that corresponds to a value
- It has a column that corresponds to a timestamp
- It has a bunch of other columns
I want to have a general transformation that allows me to:
Select an aggregate min, max over a period of time for a given category along with the other columns linked to min/max.
The stored procedure ends up being a mashup of string concatenation. Meanwhile, it just feels something is missing to make the language expressive enough.