Arrays / Nesting
Another big feature that we haven't thought about are arrays.
There's probably a small group of folks who use these, but they really like them. I've used them very successfully in the past. The newer DBs encourage using them in favor of more joins given the relative scanning vs joining performance.
They're frequently combined with structs so, for example, an Account can contain an array Addresses, each of which has a Street / City / Zip field, etc.
Generally DBs use something like ARRAY_AGG like a standard aggregation function, but instead of reducing to a number, it reduces to a row containing an array.
Malloy uses nest: extensively, I think it works quite well.
If anyone has a fuller proposal for the language design, that would be very welcome. We'd need to think about how both nesting (maybe a simple as a nest function...) and unnesting works.
This would be super helpful for me! It's often right when I get to arrays that the SQL starts to get overwhelming complex, and I'd like to switch to a better thought out language.
An example of what we'd want:
from tracks
group album_id (
aggregate titles = (title | std.collect | std.join ", ")
)
I just want to be able to do this:
SELECT a.x FROM (SELECT {'x': 1, 'y': 2, 'z': 3} AS a);
Unfortunately it doesn't seem to work:
from table
select ( a.x )
Just gives Unknown name 'a.x'
Structs/arrays are extremely useful when importing JSON.