Identifiers can contain alphanumeric characters and _ and must not start with
a number. They can be chained together with the . indirection operator, used
to retrieve a tuple from a field or a variable from a module.
hello
_h3llo
hello.world
this refers to the current relation:
from invoices
aggregate (
count this
)
Within a join, that refers to the other
table:
from invoices
join tracks (this.track_id==that.id)
this can also be used to remove any column ambiguity. For example, currently
using a bare time as a column name will fail, because it's also a type:
from invoices
derive t = time
But with this.time, we can remove the ambiguity:
from invoices
derive t = this.time
To use characters that would be otherwise invalid, identifiers can be surrounded by with backticks.
When compiling to SQL, these identifiers will use dialect-specific quotes and quoting rules.
prql target:sql.mysql
from employees
select `first name`
prql target:sql.postgres
from employees
select `first name`
prql target:sql.bigquery
from `project-foo.dataset.table`
join `project-bar.dataset.table` (==col_bax)
Identifiers of database tables can be prefixed with schema and databases names.
from my_database.chinook.albums
Note that all of following identifiers will be treated as separate table
definitions: tracks, public.tracks, my_database.public.tracks.
PRQL uses following keywords:
prql- query header more...let- variable definition more...into- variable definition more...case- flow control more...type- type declaration more...module- used internallyinternal- used internallytrue- boolean more...false- boolean more...null- NULL more...
Keywords can be used as identifiers (of columns or variables) when encased in
backticks: `case`.
Transforms are normal functions within the std namespace, not keywords. That
is, std.from is the same function as from. In the example below, the
resulting query is the same as without the std. namespace:
std.from my_table
std.select {from = my_table.a, take = my_table.b}
std.take 3