SQL Editor

Write custom SQL queries to explore your data in the Polyteia Platform.

It's useful if you want more control than the visual builder offers. You can select columns, add filters, and group or sort results exactly how you want. The editor uses DuckDB SQL syntax.

To run a query, you must first select a dataset and always end your query with a LIMIT. The maximum row number for queries is 1000.

Opening the SQL editor

You can switch to SQL mode from any insight:

  • Go to the Data tab.

  • Click the SQL button next to No-code.

This opens a text editor where you can write your SQL query.

Selecting a dataset

You always need to define which dataset the query should run on.

  • Click the dropdown labeled Available datasets.

  • Copy the dataset ID using the Copy button.

  • Paste it into your SQL code.

Example:

select *
from '{{ds_abc123xy456}}' as "Example Dataset"
limit 1000

Important: Always add LIMIT at the end of your query. The query won't run without it. 1000 is the maximum number of rows for the query.

Writing a custom query

Once the dataset is selected, you can write any valid DuckDB SQL.

Example: Select and count

select department, count(*) as total
from '{{ds_abc123xy456}}'
group by department
order by total desc
limit 1000

This example counts how many rows exist for each department and sorts them from high to low.

Exploring the dataset schema

Below the editor, you'll see a list of columns for the selected dataset. Each one shows:

  • The column name

  • The data type (like VARCHAR, DATE, DOUBLE, etc.)

Use these to help write valid queries without guessing column names.

Example types:

Column name
Type
Meaning

Name

VARCHAR

Text values

Start date

DATE

Date for filtering

Age

BIGINT

Whole number

Full-time equivalent

DOUBLE

Decimal number

Common SQL clauses

You can use all standard DuckDB clauses. Here's a quick overview:

Clause
What it does

select

Pick which columns to show

from

Define the dataset

where

Filter rows (e.g. where age > 30)

group by

Summarize data (e.g. totals per category)

order by

Sort rows (e.g. order by name asc)

limit

Always required, limits number of rows

Query validation

All SQL queries are validated before they are run. The system checks your query to make sure it is safe and follows platform rules.

Operations that could change, delete, or harm data — like DROP, DELETE, UPDATE, or creating new tables — are not allowed. If the system detects something invalid or unsafe, the query won't run.

This ensures that only safe and read-only operations are possible in the editor.

Running the query

Click the Run button to execute your query. Results appear in the table on the left.

If nothing shows up:

  • Check for typos in column names.

  • Make sure the dataset ID is correct.

  • Confirm you added limit 1000.

If still empty, your query might return no rows based on the filters.

Switching back to visual mode

Want to use the builder again?

  • Click No-code next to SQL.

  • This resets your query and returns to the drag-and-drop interface.

Note: You will lose your current SQL query if you switch.

Zuletzt aktualisiert

War das hilfreich?