by vendiddy · 4y ago · 0 comments
It seems like you're suggesting that someone could design a functional-style programming language that compiles to SQL.
2 & 3 are my biggest pain points. I can't just extract functions like I can with a regular programming language. Instead, SQL queries get increasingly complex with no great tools to manage that.
For 3, products like https://materialize.com/ look interesting for being able to create derived materialized views that can efficiently be kept up to date.
For instance, a "top 10" function that could be re-used on any table (apologies for my pseudo types and code):
selectTop10 : Column -> Table -> Table
selectTop10 orderByColumn table =
SQL.selectAllFrom table
|> orderDescBy orderByColumn
|> limit 10
limit : Int -> Table -> Table
limit n rows =
SQL.limitBy n rows
orderDescBy : Column -> Table -> Table
orderDescBy orderByColumn rows =
SQL.orderBy [orderByColumn] SQL.Ordering.Desc rowsAnd that's exactly what you're able to do in most of the modern data warehouse services such as Snowflake. Inferences can be contained within internal/external user defined functions.
This is very reminiscent of made the big-data/map-reduce movement so notable, sending your query to the data instead of moving your data to the query. Sending your model to the data, instead of sending the data to the model.
SELECT Id,col1,col2
FROM
(
SELECT
Id
,col1
,col2
,row_number () over (partition by columnkey1, columnkey2 order by anycolumnwilldohere desc) as _row
FROM _table
) as anytablealiaswilldohere
WHERE _row <=10I'm saying this as with most of my experience being in SQL.
Not exactly but sort of this:
http://blog.hydromatic.net/2020/02/25/morel-a-functional-lan...