Create a custom query
When the wizard doesn't fit — analytics, reports, multi-table joins, stored-procedure calls, anything that doesn't map 1-1 to a single table — write the query by hand in the Queries view.
This page walks the editor form field by field.
Where it lives
Liberty Next → Data → Connectors → pick a connector → stage card Queries → + Add query.
The page prompts for a name, creates an empty query and opens its editor beside the list. The editor draws the query as three stage cards — What it is (label, description), Statement (SQL, writable) and Parameters — and shows the fields of the picked one.
The editor form
Field by field
name
Shown in the editor's header, not editable there. The name is set when you click + Add query and is the permission key for the query — sql:<connector>:<name>. Rename via the Rename button of the header (cross-file — every screen / menu / dictionary reference is updated in one pass; refuses to run on unsaved local edits).
Naming rules:
| Rule | Why |
|---|---|
| Letters, digits, underscores. | TOML key, URL segment and permission string in one go. |
| Starts with a letter or underscore. | Same. |
Naming conventions that scale well:
| Pattern | Example |
|---|---|
<entity>_<action> | customer_balance, invoice_send |
<verb>_<noun> | get_top_clients, mark_paid |
report_<topic> | report_monthly_revenue, report_overdue_invoices |
writable
A checkbox under the SQL, in the Statement stage.
| State | Allowed |
|---|---|
| Off (default) | SELECT and CTE-only statements. |
| On | INSERT / UPDATE / DELETE / CALL / MERGE / DDL — anything that mutates the database. |
Leave it off for read queries — the safety gate refuses non-SELECT execution otherwise. The CRUD Wizard already sets it for _put / _post / _delete; on a hand-written query you flip it yourself when needed.
sql
The Statement stage holds the SQL editor. It accepts a single statement (the common case) or a per-dialect map (+ per-dialect variants) — see Per-dialect SQL variants.
What the editor offers:
| Feature | What it does |
|---|---|
| Syntax highlighting | Keywords coloured. |
| Autocompletion | Tables after FROM / JOIN / INTO / UPDATE, columns after <table>., read from the connector's pool. Ctrl+Space opens the list. |
| Token | Inserts a value the server fills at execution: {{LOGIN}}, {{SYSDATE}}, {{SYSTIME}}, {{SYSTIMESTAMP}}, {{JDEDATE}}, {{JDETIME}}, {{PID}}, {{JOBN}} — see Parameter binding. The end of the menu, Pool schemas, inserts a schema token of the pool, so the same SQL runs against another environment's schema. |
| Wizard | Opens the SELECT builder: pick a table, its columns, the WHERE and ORDER BY clauses. |
| Run | Tries the statement on the connector's pool and shows the rows. Offered on a read statement only (SELECT, WITH). |
:name placeholders | Any :identifier in the SQL is a bind parameter — declare it in the Parameters stage. |
A few rules from how the engine binds:
- Use
:namefor parameters, never literal string interpolation. The engine binds them through the SQLAlchemy driver —'%' || :search || '%'is the LIKE pattern you want, not'%' + search + '%'. - Reserved suffix
_ORIGINALis used by the dialog Save for UPDATE WHERE matching (see Create from a database table for the convention). - A single statement per query. For chained statements, use a
CALLto a stored procedure or split into multiple Liberty queries.
params
The Parameters stage lists the declared parameters — one line per :placeholder, opened to edit it (add declares another one). Each entry carries:
| Field | What it does |
|---|---|
| Name | The placeholder name (without the colon). Matched case-insensitively. |
| Label | What the form input shows above the field. Falls back to the name when empty. |
| Default | Pre-filled value. Blank means the caller can omit it (the engine binds SQL NULL). |
| Help, Example | What to put in it, in a sentence, and an example value — shown under the field where the parameter is filled, and given to the AI assistant. |
| Choices | The only values allowed, when there are a few: the field becomes a dropdown. |
| Required | A call without a value (and without a default) is refused before the query runs. |
Adding rows here doesn't change the SQL — it just tells screens and the AI assistant how to render an input for each placeholder. Skip this block when the query has no :placeholders; the engine accepts undeclared params at runtime (a column dialog can bind any :column_name it sees).
For binding values from other screens / sources (a row click, a parent filter, a chained action), see Parameter binding.
label (What it is)
Short name shown in dropdowns elsewhere — the screen designer, the menu target picker, the action editor. Defaults to the query name.
description (What it is)
Longer text. Shows in the lists under the query's name, and as a tooltip when the operator hovers the query in the screen designer's read-query picker.
Top-bar actions
The buttons of the query editor's header:
| Action | What it does | Notes |
|---|---|---|
| ← back | Closes the editor; the list takes the whole width again (no save). | Unsaved edits stay pending — Save in the page header writes them. |
| Find usages | Lists where the query is used (screens, charts, dashboards, dictionary…). | |
| Rename | Cross-file rename. | Refuses on unsaved local edits; updates every reference. |
| Change type | Moves the query to Tables, Sequences or Lookups. | See the four kinds of queries. |
| Move | Moves the query to another SQL connector and rewrites the references. | |
| Clone | Per-query duplicate — prompts for the name of the copy. | Default suggestion <name>_copy. See Clone a query or a connector. |
| Delete | Removes the query from the connector. | A confirm modal first. |
Save and reload
The page-level Save at the top of the Connectors page commits the connector file and triggers a hot reload. The new query is callable immediately at /api/sql/<connector>/<name> (with the bound params as query-string values for GET, JSON body for writable POST).
Verifying the query works
Run, above the SQL editor, tries a read statement on the connector's pool and shows the rows — the quickest check while writing. Beyond it:
| Path | When |
|---|---|
| Use it from a screen. | When the next step is building the screen anyway. |
| Hit the REST endpoint directly. | For a quick smoke test — GET /api/sql/<connector>/<query>?from_date=2026-01-01&to_date=2026-01-31. |
| Ask the AI assistant. | "Show me the result of monthly_revenue for last month" — when the connector is open to the assistant, it runs the read query and returns the rows. |
The REST path is the fastest debug — error messages come back verbatim, and you can pass params via URL.
When to use this vs the wizard
| Use the wizard | Use the custom editor |
|---|---|
| The table exists in the DB and you want the standard CRUD shapes. | The query joins multiple tables. |
You want consistent :NAME_ORIGINAL wiring on UPDATE. | The query is a GROUP BY aggregate. |
You want a _delete keyed on the primary key. | The query returns a derived column the table doesn't have. |
| The query is a stored-procedure call. | |
The query is a write that's not a simple UPDATE / INSERT / DELETE (a MERGE, a TRUNCATE). |
What's next
- Clone a query or a connector — start from an existing query instead of from scratch.
- Parameter binding — give the
:placeholderparams labels, defaults and bound sources. - Per-dialect SQL variants — ship one query with different SQL on Postgres vs Oracle.