Finally something that should have been pointed from the very start, I’ve looked at the page but it seems I missed the showcase, thanks! Let’s do some structured and nice review by looking at some examples:
Friendly Syntax
PRQL
from order # This is a comment
filter status == "done"
sort [-amount] # sort order
SQL
SELECT
order.*
FROM
order
WHERE
status = 'done'
ORDER BY
amount DESC
Don’t see any improvement over the original SQL, filter
is just a wrapper over the where clause. On the other hand usage of ==
operator is from development world and the -amount
is a very peculiar way to dictate the order, if I didn’t know the SQL context of the order operation I would be inclined to think that this is an arithmetic operation.
Orthogonality
PRQL
from employees
# Filter before aggregations
filter start_date > @2021-01-01
group country (
aggregate [max_salary = max salary]
)
# And filter after aggregations!
filter max_salary > 100_000
SQL
SELECT
country,
MAX(salary) AS max_salary
FROM
employees
WHERE
start_date > DATE '2021-01-01'
GROUP BY
country
HAVING
MAX(salary) > 100_000
Witch one is easier to understand in your opinion (especially if we talk about people that don’t have experience in development)? I would always go for the SQL statement, since it is clearly structured, it communicates clearly the intent, while on the other hand PRQL uses this group
syntax that is very confusing in what is trying to achieve. The catch from the SQL side of course here is to know the precedence of where
and having
, but once you understand them you are good to go.
Joins
PRQL
from employees
join b=benefits [==employee_id]
join side:left p=positions [p.id==employees.employee_id]
select [employees.employee_id, p.role, b.vision_coverage]
SQL
SELECT
employees.employee_id,
p.role,
b.vision_coverage
FROM
employees
JOIN benefits AS b ON employees.employee_id = b.employee_id
LEFT JOIN positions AS p ON p.id = employees.employee_id
This one is cherry on top of the cake. In what world the PRQL join statement is more readable than the SQL one? Once again usage of peculiar operators that you need to learn and read the documentation to understand them.