Tables

We can create a table — similar to a CTE in SQL — with table:

PRQL

table top_50 = (
  from employees
  sort salary
  take 50
  aggregate (sum salary)
)

from another_table      # Starts a new pipeline

SQL

WITH table_0 AS (
  SELECT
    employees.*
  FROM
    employees
  ORDER BY
    salary
  LIMIT
    50
), top_50 AS (
  SELECT
    SUM(salary)
  FROM
    table_0
)
SELECT
  another_table.*
FROM
  another_table

In PRQL tables are far less common than CTEs are in SQL, since a linear series of CTEs can be represented with a single pipeline.

Roadmap

Currently it’s not yet possible to have an s-string as a whole table. See #376 for more details.

table a = s"""
  SELECT *
  FROM employees
"""

from a