| I think that the biggest problem with SQL is more around the actual syntax of the language and how verbose it feels to write complicated queries. I would prefer a syntax layer that can be compiled / transformed back to SQL but that does basic things like having a query start with the tables, then joins, then groupings then the final projection. Also a less cumbersome way to use the "WITH" statement to form named sub-queries. Perhaps something like: SELECT
COUNT(*) as columns,
column_type,
table_name
FROM (
SELECT c.id,
c.type AS column_type,
t.name AS table_name
FROM tables t
INNER JOIN columns c
ON t.id = c.table_id
WHERE t.system=false;
) a
HAVING COUNT(*) > 1
ORDER BY columns DESC
Being re-written as: # Use ":=" to replace WITH for named ephermal views
# Replace "WHERE" with "?", "SELECT" with "|>" at the end
non_system := tables
? system=false
|> name:table_name, is:table_id
# Replace INNER JOIN with "*="
non_system_columns := non_system.table_id *= columns.table_id
|> c.id, c.type:column_type
# GROUP BY columns are automatically generated by non-aggregated columns
column_types := non_system_columns
|> COUNT(*):columns DESC, column_type, table_name
So the final query may look like: non_system := tables ? system=false
|> name:table_name, is:table_id
non_system_columns := non_system.table_id *= columns.table_id
|> c.id, c.type:column_type
non_system_columns
|> COUNT(*):columns DESC, column_type, table_name
Any thoughts on this? |