Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

We are holding back on `let` to be used for defining a new variable, while `derive` is used to define a new column in a relation.


Understood, thanks.

But is that really different from the point of view of the developer? As long as the column is not used in the output it's just a variable.

I elaborate because I checked the examples since my first comment:

There are two derive sections in introduction.prql.

  derive [  # This adds columns / variables.
    gross_salary = salary + payroll_tax,
    gross_cost = gross_salary + benefits_cost # Variables can use other variables.
  ]
Note the comments about "columns / variables" and "Variables can use other variables", so the distinction is probably not very clear even now.

From my point of view that would be

  let gross_salary = salary + payroll_tax
  let gross_cost = gross_salary + benefits_cost
Then I'd get gross_salary and gross_cost in the result or not, according to the select I'm doing at the end. [1]

By the way, in the examples I saw

  select [name, salary, average_country_salary]
which has some unnecessary brackets. Why not just omitting them?

  select name, salary, average_country_salary
Same for the parentheses in

  aggregate average_country_salary = (average salary)
Maybe omitting [ ] and ( ) would make the parser too complex but I'm all in to offload work to computers instead of to developers :-)

And why not only one type of brackets? Example: the join clause

  join average_salaries [==country]
which gets compiled to

  JOIN average_salaries ON newest_employees.country = average_salaries.country
Why square brackets there instead of round ones?

That's a condition and we're conditioned to put conditions inside (), as in if () {} else {}

And omit == by default, so

  join average_salaries (country)
[1] Edit: maybe you can add a negative select, to remove columns from the output. Maybe:

  remove col1, col2
That would be handy where there are 100 columns and one wants to remove only 5 of them. No need to enumerate the other 95.


Am I understanding correctly that it's because there's no "select" at the end that chooses variables/expressions to become columns in the output? Instead, you specify the output columns as you go? In LINQ we only have "let" and no "derive", but instead we have to say "select" at the end to list the columns.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: