Raw SQL
Learn how to write and run raw SQL in Draxlr, format your queries, add variables with double curly braces, filter by date ranges, make filters optional with bracketed sections, and get help from AI.
This guide will walk you through running raw SQL queries directly in Draxlr. Follow the steps below to switch to Raw Query mode, write queries, and view results.

In Browse Data, click Switch to Raw Query.
How to run Raw SQL Code?
1. Open the Raw SQL Editor
In Browse Data, click Switch to Raw Query at the top of the left panel. You can also click Create a new Query and choose SQL Query.
If you switch while a Query Builder query is open, its SQL is copied into the editor and run, so you can keep editing it by hand.
2. Enter Your SQL Query
In the editor area, type your SQL query. Table and column names autocomplete as you type. For example:
SELECT OrderID, OrderDate, ShipCity, ShipCountry, Freight
FROM Orders
WHERE EmployeeID = 2
ORDER BY OrderDate DESC;
The buttons below the editor help you write:
- View Schema shows the tables and columns in your database.
- Format tidies up the query. You can also press Ctrl + Shift + F.
- The expand icon opens the editor in fullscreen.
- Quick tips shows the variable, date range and optional section syntax. Once your query has a variable, open the tips again with the Tips button.
3. Add Variables (Optional)
Wrap a name in double curly braces to turn part of the query into a variable, for example {{employeeId}}:
SELECT OrderID, OrderDate, ShipCity, ShipCountry, Freight
FROM Orders
WHERE EmployeeID = {{employeeId}};
A field for each variable appears below the editor. Variable names can only contain letters, with no numbers, spaces or special characters.
4. Set the Variable Data Type and Value
For each variable, choose a data type and enter a value. The data types are Text, Numeric, Boolean, Date, Date-time and Time. For Boolean, pick true or false.
5. Execute the Query
Click Execute Query, or press Ctrl + Enter in the editor. The results appear on the right as a table.
From there, you can:
- Switch to Dashboard Table, Pivot Table or Graph to view the results differently.
- Export the results.
- Click Save Query to reuse the query on dashboards and in automations.
Getting Help from AI
Click Get help from AI below the editor, describe what you want to change (for example, "show only orders shipped to France"), and click Send. The AI updates the query in the editor.
- Click View AI changes to compare the new query with the previous one.
- Click Revert to original query to undo the AI's changes.
See Edit SQL with AI for a walkthrough.
If a query fails, click How to fix this? in the error panel. The AI explains the error and suggests a corrected query you can run with Execute suggestion. See Fix SQL errors.
Filtering by a Date Range
To filter a date column between a start and an end date, use {{dateRange:<field name>}} as a condition in your query, where <field name> is the column to filter on:
SELECT * FROM `Orders`
WHERE {{dateRange:OrderDate}};
The variable shows a date range picker in the variables panel instead of a single value field:
- Choose the data type: Date or Date-time.
- Pick the start and end dates, or use a preset: Today, This Week, Last Week, This Month, Last Month or This Year.
- Click Execute Query.
Draxlr replaces the variable with a range condition on that field before the query runs:
| Data type | Picked range | Condition used |
|---|---|---|
| Date | 2024-01-01 to 2024-01-31 | OrderDate >= '2024-01-01' AND OrderDate < '2024-02-01' |
| Date-time | 2024-01-01 09:00:00 to 2024-01-31 18:00:00 | OrderDate >= '2024-01-01 09:00:00' AND OrderDate <= '2024-01-31 18:00:00' |
With the Date type the whole end date is included, even when the column also stores a time.
You can add the table name or alias in front of the field when your query joins tables:
SELECT o.OrderID, c.CompanyName
FROM `Orders` o
JOIN `Customers` c ON c.CustomerID = o.CustomerID
WHERE {{dateRange:o.OrderDate}};
Use it as a full condition:
The date range variable becomes a complete condition, so place it where a
condition is expected — after WHERE, AND or OR — and not after an
operator such as = or BETWEEN.
Field names:
The field name can contain letters, numbers and underscores, with an optional
table name or alias (o.OrderDate). Wrap names that contain spaces in
backticks or square brackets, like `Order Date` or [Order Date].
Double-quoted names are not supported.
To make the date range optional, wrap it in [[ ... ]] as described in the next section. To control it from a dashboard, use a Raw SQL Query Variable filter with Use date range turned on.
Making a Section Optional
Sometimes you want part of your query to run only when a variable has a value — an optional filter, for example. Wrap that part of the query in double square brackets [[ ... ]] to make it optional.
When the variable inside an optional section is left empty, the entire section is removed before the query runs. When you provide a value, the section is included and the variable is substituted as usual.
SELECT * FROM `Orders`
[[WHERE `Orders`.`EmployeeID` = {{employeeId}}]];
- Leave employeeId empty → the query runs as
SELECT * FROM Ordersand returns all rows. - Enter a value → the
WHEREclause is applied.
Any variable used inside an optional section shows an Optional badge in the variables panel, and its value field can be left blank.
Combining multiple optional filters
To use several optional filters together, start with a clause that is always true (such as WHERE 1 = 1) and put each filter in its own [[ ... ]] block:
SELECT * FROM `Orders`
WHERE 1 = 1
[[AND `Orders`.`EmployeeID` = {{employeeId}}]]
[[AND `Orders`.`ShipCountry` = {{country}}]];
Each block is included independently, based on whether its variable has a value.
Optional date range
A date range works the same way. When no range is picked, the section is skipped and all rows are returned:
SELECT * FROM `Orders`
WHERE 1 = 1
[[AND {{dateRange:OrderDate}}]];
Good to know:
If an optional section contains more than one variable, the section is included only when all of its variables have a value. If any of them is left empty, the whole section is skipped.
Switching Back to the Query Builder
Click Switch to Query Builder to go back. Your raw SQL isn't converted into Query Builder steps, so any changes made in the editor are lost. If you've edited a saved raw query without saving it, Draxlr asks you to confirm first.
Summary
- Switch to Raw Query mode.
- Write or paste your SQL query, and format it for readability.
- (Optional) Add variables for dynamic inputs.
- (Optional) Use
{{dateRange:<field name>}}to filter a date column by a start and end date. - (Optional) Wrap a clause in
[[ ]]to skip it when its variable is empty. - Execute the query to view results, then save it to reuse on dashboards.
- Use Get help from AI when you need a hand writing or changing the query.
This allows you to explore your data flexibly using raw SQL while benefiting from Draxlr’s interactive environment.
