Skip to main content

Querying Data

The query panel is where you move beyond simple previews and start asking precise questions of your data. Located at the bottom of the Data View workspace, it accepts both PRQL and DQL queries and returns results directly into the data grid.


Opening the Query Panel

The query panel is visible by default when you open a Data View. If it is hidden, use the layout toggle in the toolbar to restore it. The panel consists of three parts:

PartDescription
Language selectorChoose between PRQL and DQL before writing your query.
Editor areaA text editor where you write and edit your query.
Run buttonExecutes the current query and displays results in the data grid above.

Choosing a Query Language

Datafi supports two query languages. You select the active language from the dropdown in the query panel before running a query.

PRQL (Pipelined Relational Query Language)

PRQL is a modern, pipeline-based language that compiles to database-specific SQL. It reads top to bottom, with each line transforming the dataset from the previous line. PRQL is ideal if you prefer a concise, readable syntax.

from customers
filter region == "US"
select {customer_id, first_name, last_name, email}
sort created_at
take 50

Datafi compiles this PRQL into the appropriate SQL dialect for your connected datasource before executing it.

DQL (Datafi Query Language)

DQL uses a SQL-compatible syntax that feels familiar to anyone who has written SQL. It supports SELECT, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, aggregate functions, and more.

SELECT customer_id, first_name, last_name, email
FROM customers
WHERE region = 'US'
ORDER BY created_at
LIMIT 50
Which Language Should You Use?

If you are comfortable with SQL, DQL is the fastest path. If you want a more readable, pipeline-oriented approach, try PRQL. Both produce the same results -- the choice is a matter of preference.


Writing and Running a Query

Follow these steps to execute a query in the Data View:

  1. Select your datasource -- In the schema panel, click the datasource you want to query. The query panel targets this source.
  2. Choose the language -- Select PRQL or DQL from the language dropdown.
  3. Write your query -- Type or paste your query into the editor area.
  4. Run the query -- Click the Run button or use the keyboard shortcut to execute. Results appear in the data grid.

Example: Basic DQL Query

SELECT order_id, customer_id, total_amount, order_date
FROM orders
WHERE order_date >= '2025-01-01'
ORDER BY total_amount DESC
LIMIT 100

Example: Basic PRQL Query

from orders
filter order_date >= @2025-01-01
select {order_id, customer_id, total_amount, order_date}
sort {-total_amount}
take 100

Both queries return the same result set -- the 100 highest-value orders placed on or after January 1, 2025, sorted by amount in descending order.


Query Panel Features

Syntax Highlighting

The editor provides syntax highlighting for both PRQL and DQL, making it easier to read and spot errors in your queries.

Error Messages

If your query contains a syntax error or references a table or column that does not exist, the query panel displays a descriptive error message below the editor. The message includes the line number and a brief explanation of the problem.

Result Count

After a query executes, the toolbar displays the number of rows returned. This helps you gauge whether your filters are too broad or too narrow without scrolling through the entire result set.


Query Best Practices

  • Start narrow -- Use LIMIT (DQL) or take (PRQL) to restrict results while you iterate on your query. Remove the limit once you are confident the query is correct.
  • Filter early -- Apply WHERE or filter clauses to reduce the amount of data transferred from the source. This improves performance, especially on large tables.
  • Use the schema panel -- Before writing a query, expand the target table in the schema browser to confirm column names and data types. This avoids typos and type-mismatch errors.
  • Iterate -- The query panel retains your last query. You can modify it and re-run as many times as needed.

Working with Results

Query results populate the data grid in the center of the workspace. From there, you can:

  • Sort columns by clicking column headers (ascending or descending).
  • Filter rows using the filter panel to narrow displayed results further.
  • Export to CSV for use in external tools.
  • Share the Data View so colleagues can see the same query and results.

All of these actions are covered in detail in Filtering and Exporting.


Next Steps