Skip to main content

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​

[connectors.crm] · sqlSETTINGSpool crmTABLES3 table(s)QUERIES3 query(ies)SEQUENCES1LOOKUPS2⌕ filter 3…customer_balanceBalance per customermonthly_revenueRevenue per monthpurge_old_logsDelete logs older than a year← backmonthly_revenueFind usagesRenameChange typeMoveCloneDeleteWHAT IT ISMONTHLY_REVENUESTATEMENTSELECTPARAMETERS2 declaredSQL ∗{} Token✦ Wizard▷ Run1SELECT date_trunc('month', invoice_date) AS MONTH,2 SUM(total_ht) AS REVENUE3FROM invoices4WHERE invoice_date BETWEEN :FROM_DATE AND :TO_DATE5GROUP BY 1 ORDER BY 1+ per-dialect variantsWRITABLEdisabledAllow non-SELECT statements (INSERT / UPDATE / DELETE).The list stays besideone click to another queryThree stageswhat it is, statement, parametersServer tokens{{LOGIN}}, {{SYSDATE}}, schemasPer-dialect variantsone statement per databaseQuery buttonsusages, rename, type, move…Wizard · RunSELECT builder · try a readWritableoff: SELECT only

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:

RuleWhy
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:

PatternExample
<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.

StateAllowed
Off (default)SELECT and CTE-only statements.
OnINSERT / 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:

FeatureWhat it does
Syntax highlightingKeywords coloured.
AutocompletionTables after FROM / JOIN / INTO / UPDATE, columns after <table>., read from the connector's pool. Ctrl+Space opens the list.
TokenInserts 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.
WizardOpens the SELECT builder: pick a table, its columns, the WHERE and ORDER BY clauses.
RunTries the statement on the connector's pool and shows the rows. Offered on a read statement only (SELECT, WITH).
:name placeholdersAny :identifier in the SQL is a bind parameter — declare it in the Parameters stage.

A few rules from how the engine binds:

  • Use :name for parameters, never literal string interpolation. The engine binds them through the SQLAlchemy driver — '%' || :search || '%' is the LIKE pattern you want, not '%' + search + '%'.
  • Reserved suffix _ORIGINAL is 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 CALL to 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:

FieldWhat it does
NameThe placeholder name (without the colon). Matched case-insensitively.
LabelWhat the form input shows above the field. Falls back to the name when empty.
DefaultPre-filled value. Blank means the caller can omit it (the engine binds SQL NULL).
Help, ExampleWhat 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.
ChoicesThe only values allowed, when there are a few: the field becomes a dropdown.
RequiredA 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:

ActionWhat it doesNotes
← backCloses the editor; the list takes the whole width again (no save).Unsaved edits stay pending — Save in the page header writes them.
Find usagesLists where the query is used (screens, charts, dashboards, dictionary…).
RenameCross-file rename.Refuses on unsaved local edits; updates every reference.
Change typeMoves the query to Tables, Sequences or Lookups.See the four kinds of queries.
MoveMoves the query to another SQL connector and rewrites the references.
ClonePer-query duplicate — prompts for the name of the copy.Default suggestion <name>_copy. See Clone a query or a connector.
DeleteRemoves 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:

PathWhen
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 wizardUse 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​