Ask HN: Does anyone else think SQL needs help?
11 by fny | 19 comments on Hacker News.
I have been writing a decent amount of SQL for three years now, and while the paradigm is extremely powerful, the language lends itself to unmaintainable spaghetti code quickly. Fundamentally, SQL lacks meaningful abstraction, and there's no sane way to package very common operations. Say you want to find elements in a row that correspond to some maximum value when grouped by date. Today, you'd need to write something like this EVERY SINGLE TIME: ``` SELECT sd1.sale_person_id, sd1.sale_person_name, sd1.no_products_sold, sd1.commission_percentage, sd1.sales_department FROM sales_department_details sd1 INNER JOIN (SELECT sale_person_id, MAX(no_products_sold) AS no_products_sold FROM sales_department_details GROUP BY sale_person_id) sd2 ON sd1.sale_person_id = sd2.sale_person_id AND sd1.no_products_sold = sd2.no_products_sold; ``` Wouldn't something like this be nicer? ``` SELECT sale_person_id, max(no_products_sold) as max_sold, link(sale_person_name, max_sold), FROM sales_department_details ``` Frankly, it seems like some sort of macro system is needed. Perhaps the SQL compiles into the above?
No comments:
Post a Comment