Query builder
Build a query from the schema, add joins, grouping, filters, and sorting, set a row limit, and work with the fetched sample.
The builder creates queries from the loaded schema with inner joins, nested filters, sorting, column grouping, and a row limit, including ALL. It validates each query against the schema and compiles it with bound parameters. Limits are covered in Limits & risk model.
Schema first
Map is its own screen in the sidebar. It shows tables, keys, indexes, and referenced external tables. System schemas are omitted. The map is read-only and does not rewrite the query you are building. The builder also has a Schema rail for adding tables to the canvas.
Joins and grouping
Joins are INNER JOIN on column equality (a.x = b.y). Each join
column must be the leading key of an equality-capable index, or the join must be a complete
foreign key.
Group by in the builder is SQL grouping of columns, not Explore aggregations.
When grouping is on, every selected column and every sort column has to be in the group. COUNT and other aggregates belong in Explore, on the sample you already fetched.
Filters and distinct rows
Filters are nested groups, combined with AND or OR. The operator menu follows the column type:
- Text.
=,<>, contains, contains (case-insensitive), does not contain, starts with, ends with,IN,NOT IN,IS NULL,IS NOT NULL,IS EMPTY, andIS NOT EMPTY. - Numbers. Comparisons,
BETWEEN,IN, and null checks. - Dates. Comparisons,
BETWEEN, and null checks. - Booleans, binary, JSON, and other types.
=,<>, and null checks.
Date filters accept a date such as 2024-01-01. Timestamp filters also accept a
space-separated timestamp such as 2024-01-01 09:30 or an ISO timestamp such as 2024-01-01T09:30:00. A date alone means midnight.
Distinct rows is a switch. With it on, every sort column has to be selected. The builder reports that requirement. Add the missing columns, or remove the sorts.
Running a query
The button is labeled Run. Before execution, safe-db scores the query from the schema, then asks the database for a plan. See Limits & risk model.
Layout and small windows
The builder stays usable at the 960x600 minimum window size. With the sidebar expanded, the toolbar wraps the connection controls and Run as groups instead of splitting labels.
Filters sit in a height-bounded scrolling strip above the canvas, so a long IN list
cannot cover the table cards. Query options opens a dialog with distinct rows, grouping,
sorting, and joins.
BETWEEN fields stay together with their from, and, and to labels. Each wrapped IN value keeps its remove button.
Table cards show column names at every width. A card shows column types once it is wide enough. On a narrower card, hover a column name to see its type.
Working with the sample
Results arrive as a sample. The row and size caps are in Limits & risk model. Results stay visible after a run. When the query changes, the previous sample is marked Stale until you run again. Open Explore for Pivot, Worksheet, and Visualization.