DBQC API Guide
DBQC compiles JSON query definitions into SQL for PostgreSQL, MySQL, SQLite, and DuckDB (Oracle, SQL Server, and DB2 with DBQC Pro). You POST a JSON body describing your query as a tree of nodes, and the compiler returns a CTE-based SQL string with parameterized inputs. That output is intentionally handed back to the driver and transaction handling your application already uses; DBQC does not execute it.
Authentication
Every request to the compile endpoint requires an API key passed as the x-api-key header. Get your key from your account page or from the welcome email after subscribing.
Set it as an environment variable (all client libraries read this automatically):
export DBQC_KEY=your-key-here
Or pass it directly in the header:
curl -X POST https://api.dbqc.volvwealth.com/compile \
-H "Content-Type: application/json" \
-H "x-api-key: $DBQC_KEY" \
-d '{"terminal": { ... }, "target": "psql"}'
Each client library also accepts the key as a parameter:
| Language | Environment variable | Code parameter | CLI flag |
|---|---|---|---|
| Python | DBQC_KEY |
compile(source, key="...") |
--key |
| TypeScript | DBQC_KEY |
compile(source, "psql", url, key) |
--key |
| Java | DBQC_KEY |
compile(source, target, url, key) |
--key |
| Rust | DBQC_KEY |
source.compile_with_key(target, url, key) |
— |
Quick Start
POST a query definition:
{
"type": "filter",
"input": {
"type": "table",
"name": "users",
"dbSchema": "public",
"heading": [
{"name": "id", "type": "uuid"},
{"name": "name", "type": "text"},
{"name": "email", "type": "text", "nullable": true}
]
},
"pred": {
"type": "col_ref",
"source": {"type": "table", "name": "users", "...": "..."},
"name": "id",
"tpe": {"type": "uuid"}
}
}
Response (always HTTP 200 — check errors to determine success):
{
"query": {
"sql": "WITH \"users\" AS (...) SELECT * FROM ...;",
"paramOrder": [
{"name": "user_id", "type": "uuid", "nullable": false}
],
"rowSchema": [
{"name": "id", "type": "uuid", "nullable": false},
{"name": "name", "type": "text", "nullable": false},
{"name": "email", "type": "text", "nullable": false}
]
},
"errors": [],
"warnings": []
}
On success, query contains the compiled SQL and schema; errors is empty. On failure, query is null and errors contains human-readable error messages. warnings is always present and may contain non-fatal diagnostics in both cases.
How It Works
Your JSON defines a tree of Source nodes (tables, filters, joins, aggregates, etc.). Each node references its inputs. The compiler:
- Walks the tree to extract all dependencies
- Topologically sorts them into a linear execution order
- Emits each node as a named CTE
- Returns the final SQL, parameter positions, and output schema
You model what you want relationally and do not need to hand-manage CTE ordering or parameter positions. The compiler handles that construction work, then returns inspectable SQL for your existing execution stack.
Review comments
DBQC can carry SQL comments as render-only trivia. They remain in the generated SQL so a team can review context, migration notes, and opaque vendor directives alongside the query, but they do not change validation, parameters, schemas, or query comparison.
For JSON clients, use an "annotated" Source or "annotated_expr" expression. before and after are arrays of complete SQL comment tokens, retained verbatim (apart from separating whitespace added by the renderer):
{
"type": "annotated",
"input": {"type": "table", "name": "items", "dbSchema": "public", "heading": []},
"before": ["/* Imported from the reconciliation service */"],
"after": []
}
DBQC does not translate comment-form vendor directives such as /+ ... /; it carries them as opaque SQL text. When moving between database vendors, review those directives because the target database may ignore them.
Types
SqlType
Column and expression types are JSON objects with a "type" discriminator.
Simple types (no parameters):
| type value | PostgreSQL | Example |
|---|---|---|
"bool" |
bool |
true/false |
"text" |
text |
strings |
"int2" |
smallint |
small integers |
"int4" |
integer |
integers |
"int8" |
bigint |
large integers |
"float4" |
real |
single-precision |
"float8" |
double precision |
double-precision |
"uuid" |
uuid |
UUIDs |
"date" |
date |
dates |
"timestamp" |
timestamptz |
timestamps |
"interval" |
interval |
time intervals |
"jsonb" |
jsonb |
JSON data |
Simple types are written as {"type": "text"}, {"type": "int4"}, etc.
Parameterized types include their parameters as fields:
{"type": "char", "length": 10}
{"type": "varchar", "length": 255}
{"type": "numeric", "precision": 10, "scale": 2}
{"type": "enum", "name": "user_status"}
{"type": "array", "element": {"type": "text"}}
FieldType
A column's type and nullability, encoded as an object:
{"type": "uuid"}
Non-null is the default — omit "nullable" entirely (do NOT write "nullable": false). Add "nullable": true for nullable columns: {"type": "text", "nullable": true}. Parameterized types include their parameters in the type string: {"type": "varchar(255)"}, {"type": "numeric(10,2)"}, {"type": "char(10)"}. Arrays use bracket notation: {"type": "text[]"}, {"type": "int4[]"}. Enums use {"type": "enum(name)"}.
Heading
An ordered array of column objects, each with a name, type, and optional nullability:
[
{"name": "id", "type": "uuid"},
{"name": "name", "type": "text"},
{"name": "email", "type": "text", "nullable": true}
]
Source Nodes
Every query is a tree of Source nodes. Each node has a "type" discriminator field with a snake_case value.
Table
References a physical database table.
{
"type": "table",
"name": "users",
"dbSchema": "public",
"heading": [
{"name": "id", "type": "uuid"},
{"name": "name", "type": "text"}
]
}
Params
Declares query parameters. Parameters become positional ($1, $2, ...) in the output SQL.
{
"type": "params",
"schema": [
{"name": "user_id", "type": "uuid"}
]
}
Filter (WHERE)
{
"type": "filter",
"input": { "...source..." },
"pred": { "...expr..." }
}
Project (SELECT columns)
Selects and transforms columns. Keys are output column names, values are expressions.
{
"type": "project",
"input": { "...source..." },
"mapping": {
"full_name": { "...expr..." },
"is_active": { "...expr..." }
}
}
Join
{
"type": "join",
"left": { "...source..." },
"right": { "...source..." },
"on": { "...expr (boolean)..." },
"leftOuter": false,
"rightOuter": false
}
| leftOuter | rightOuter | Result |
|---|---|---|
| false | false | INNER JOIN |
| true | false | LEFT JOIN |
| false | true | RIGHT JOIN |
| true | true | FULL OUTER JOIN |
Ordered (ORDER BY / LIMIT / OFFSET)
{
"type": "ordered",
"input": { "...source..." },
"orderBy": [
{"expr": { "...expr..." }, "dir": "asc"},
{"expr": { "...expr..." }, "dir": "desc_nulls_last"}
],
"limit": 10,
"offset": null
}
Direction values: "asc", "desc", "asc_nulls_first", "asc_nulls_last", "desc_nulls_first", "desc_nulls_last".
Aggregate (GROUP BY)
{
"type": "aggregate",
"input": { "...source..." },
"groupBy": [
{"type": "col_ref", "source": {"...orders source..."}, "name": "user_id", "tpe": {"type": "uuid"}}
],
"aggregates": {
"user_id": {"type": "col_ref", "source": {"...orders source..."}, "name": "user_id", "tpe": {"type": "uuid"}},
"total_spent": {"type": "agg_expr", "func": "sum", "arg": {"type": "col_ref", "source": {"...orders source..."}, "name": "amount", "tpe": {"type": "float8"}}, "distinct": false, "tpe": {"type": "float8"}, "filter": null},
"order_count": {"type": "agg_expr", "func": "count", "arg": null, "distinct": false, "tpe": {"type": "int8"}, "filter": null}
},
"having": null
}
Distinct / Distinct On
Plain distinct:
{
"type": "distinct",
"input": { "...source..." },
"on": []
}
Distinct on specific columns (Postgres-specific):
{
"type": "distinct",
"input": { "...source..." },
"on": [
{"type": "col_ref", "source": {"...users source..."}, "name": "email", "tpe": {"type": "text"}}
]
}
Set Operations
Six separate operations — deduplicating and bag-accumulating variants have different semantics (affecting termination in recursive queries), so they are distinct types rather than a boolean flag.
{"type": "union", "left": { "..." }, "right": { "..." }}
{"type": "union_all", "left": { "..." }, "right": { "..." }}
| Type | SQL | Semantics |
|---|---|---|
union |
UNION |
Deduplicates across both sides |
union_all |
UNION ALL |
Keeps all rows (bag semantics) |
intersect |
INTERSECT |
Rows in both sides (dedup) |
intersect_all |
INTERSECT ALL |
Bag intersection |
except |
EXCEPT |
Rows in left but not right (dedup) |
except_all |
EXCEPT ALL |
Bag difference |
Both sides must have matching schemas.
Values (ad-hoc inline relation)
Constructs a relation from literal rows without requiring a physical table. Useful for test data, reference tables, and structured IN-clauses.
{
"type": "values",
"rows": [
{"id": {"type": "literal", "value": 1, "tpe": {"type": "int4"}},
"name": {"type": "literal", "value": "Alice", "tpe": {"type": "text"}}},
{"id": {"type": "literal", "value": 2, "tpe": {"type": "int4"}},
"name": {"type": "literal", "value": "Bob", "tpe": {"type": "text"}}}
]
}
Schema is derived from the first row. All rows must have the same column names.
Locked (FOR UPDATE / FOR SHARE)
Row-level locking on SELECT queries. PostgreSQL and MySQL emit the lock clause; SQLite silently drops it (file-level locking only).
{
"type": "locked",
"input": { "...source..." },
"lock": {"mode": {"type": "for_update"}, "nowait": false, "skipLocked": false}
}
| mode type | SQL |
|---|---|
for_update |
FOR UPDATE |
for_share |
FOR SHARE |
Options: nowait: true adds NOWAIT, skipLocked: true adds SKIP LOCKED.
LetRec (recursive CTE / WITH RECURSIVE)
Recursive query using letrec semantics. The step references the CTE via a ref node for self-reference.
{
"type": "let_rec",
"name": "ancestors",
"seed": { "...source producing initial rows..." },
"step": {
"type": "union_all",
"left": {"type": "ref", "name": "ancestors", "heading": { "..." }},
"right": { "...source joining ref to parent table..." }
},
"body": {"type": "ref", "name": "ancestors", "heading": { "..." }}
}
The step's set operation determines termination:
union_all: accumulates all rows (tree traversal)union: deduplicates across iterations (cycle-safe graph traversal)
Use let_rec_distinct instead of let_rec when the step uses union (set-deduplicating) semantics.
LATERAL Join
Set lateral: true on a Join to let the right side reference columns from the left side. Enables correlated derived tables.
{
"type": "join",
"left": { "...source..." },
"right": { "...source referencing left columns..." },
"on": { "...expr..." },
"leftOuter": true,
"rightOuter": false,
"lateral": true
}
Update
{
"type": "update",
"table": { "...table source..." },
"sets": {
"status": {"type": "literal", "value": "active", "tpe": {"type": "text"}}
},
"from": null,
"where": { "...expr..." },
"returning": ["id", "status"]
}
from is an optional Source for multi-table updates (UPDATE ... FROM ...).
InsertFrom (INSERT ... SELECT)
{
"type": "insert_from",
"table": { "...table source..." },
"source": { "...source to select from..." },
"onConflict": null,
"returning": ["id"]
}
InsertValues
{
"type": "insert_values",
"table": { "...table source..." },
"values": [
{
"id": {"type": "literal", "value": "abc-123", "tpe": {"type": "uuid"}},
"name": {"type": "literal", "value": "Alice", "tpe": {"type": "text"}}
},
{
"id": {"type": "literal", "value": "def-456", "tpe": {"type": "uuid"}},
"name": {"type": "literal", "value": "Bob", "tpe": {"type": "text"}}
}
],
"onConflict": null,
"returning": ["id", "name"]
}
Delete
{
"type": "delete",
"table": { "...table source..." },
"using": null,
"where": { "...expr..." },
"returning": ["id"]
}
using is an optional Source for multi-table deletes (DELETE ... USING ...).
RawSource (escape hatch)
Inject raw SQL when the algebra doesn't cover your case:
{
"type": "raw_source",
"sql": "SELECT generate_series(1, 10) AS n",
"columns": [
{"name": "n", "type": "int4"}
],
"deps": []
}
OnConflict
Used in InsertFrom and InsertValues:
null
{"type": "do_nothing", "targets": ["id"]}
{
"type": "do_update",
"targets": ["id"],
"sets": {
"name": {"type": "literal", "value": "Updated", "tpe": {"type": "text"}}
}
}
For MySQL, do_update must use an explicit empty targets array. It emits ON DUPLICATE KEY UPDATE, which runs for any duplicate unique key. Named targets are rejected because MySQL cannot name a specific conflicting key; MySQL do_nothing is also rejected because INSERT IGNORE suppresses non-conflict errors.
Expressions
Expressions define predicates, projections, and computations. Each has a "type" discriminator field with a snake_case value. The SqlType of an expression is in the "tpe" field as a SqlType object.
ColRef — column reference
{"type": "col_ref", "source": {"...source..."}, "name": "email", "tpe": {"type": "text"}}
source is the full Source object (table, params, etc.) that the column comes from.
Literal — constant value
{"type": "literal", "value": "active", "tpe": {"type": "text"}}
{"type": "literal", "value": 42, "tpe": {"type": "int4"}}
{"type": "literal", "value": true, "tpe": {"type": "bool"}}
BinaryExpr — two-operand operations
{
"type": "binary_expr",
"left": { "...expr..." },
"op": "eq",
"right": { "...expr..." },
"tpe": {"type": "bool"}
}
Operators:
| Op | SQL | Use | ||
|---|---|---|---|---|
eq |
IS NOT DISTINCT FROM |
null-safe equals | ||
neq |
IS DISTINCT FROM |
null-safe not-equals | ||
lt |
< |
less than | ||
gt |
> |
greater than | ||
lte |
<= |
less or equal | ||
gte |
>= |
greater or equal | ||
and |
AND |
logical and | ||
or |
OR |
logical or | ||
plus |
+ |
addition | ||
minus |
- |
subtraction | ||
multiply |
* |
multiplication | ||
divide |
/ |
division | ||
like |
LIKE |
pattern match | ||
i_like |
ILIKE |
case-insensitive pattern | ||
concat |
`\ | \ | ` | string concatenation |
array_contains |
@> / dialect-specific |
array containment | ||
json_extract |
-> / dialect-specific |
JSON sub-value extraction | ||
json_extract_text |
->> / dialect-specific |
JSON text extraction |
Note: eq uses IS NOT DISTINCT FROM (null-safe). Two NULLs compare as equal.
UnaryExpr — single-operand operations
{
"type": "unary_expr",
"inner": { "...expr..." },
"op": "is_null",
"tpe": {"type": "bool"}
}
Operators: "not", "is_null", "is_not_null".
AggExpr — aggregate functions
{
"type": "agg_expr",
"func": "count",
"arg": {"type": "col_ref", "source": {"...orders source..."}, "name": "id", "tpe": {"type": "uuid"}},
"distinct": true,
"tpe": {"type": "int8"},
"filter": {
"type": "binary_expr",
"left": {"type": "col_ref", "source": {"...orders source..."}, "name": "status", "tpe": {"type": "text"}},
"op": "eq",
"right": {"type": "literal", "value": "completed", "tpe": {"type": "text"}},
"tpe": {"type": "bool"}
}
}
func:"count","sum","avg","min","max","array_agg","json_agg"arg: null forCOUNT(*), otherwise an expressiondistinct: true forCOUNT(DISTINCT ...)filter: optional predicate forFILTER (WHERE ...)
WindowExpr — window functions
{
"type": "window_expr",
"inner": {"type": "rank_expr", "func": "row_number"},
"partitionBy": [
{"type": "col_ref", "source": {"...users source..."}, "name": "dept_id", "tpe": {"type": "uuid"}}
],
"orderBy": [
{"expr": {"type": "col_ref", "source": {"...users source..."}, "name": "salary", "tpe": {"type": "float8"}}, "dir": "desc_nulls_last"}
],
"tpe": {"type": "int8"}
}
RankExpr — ranking functions
{"type": "rank_expr", "func": "row_number"}
{"type": "rank_expr", "func": "rank"}
{"type": "rank_expr", "func": "dense_rank"}
Always used inside a WindowExpr.
FuncExpr — any SQL function
Call any built-in or user-defined function:
{
"type": "func_expr",
"name": "GREATEST",
"args": [
{"type": "col_ref", "source": {"...users source..."}, "name": "watermark", "tpe": {"type": "text"}},
{"type": "col_ref", "source": {"...params source..."}, "name": "milestone", "tpe": {"type": "text"}}
],
"tpe": {"type": "text"}
}
Common functions: LOWER, UPPER, TRIM, CONCAT, LENGTH, SUBSTRING, DATE_TRUNC, DATE_PART, NOW, NULLIF, GREATEST, LEAST, COALESCE (also available as a dedicated Coalesce expr).
CastExpr — type casting
{
"type": "cast_expr",
"expr": {"type": "col_ref", "source": {"...users source..."}, "name": "age_str", "tpe": {"type": "text"}},
"targetType": {"type": "int4"}
}
Emits CAST(expr AS integer).
Coalesce — null fallback
{
"type": "coalesce",
"inner": {"type": "col_ref", "source": {"...users source..."}, "name": "nickname", "tpe": {"type": "text"}},
"default": {"type": "literal", "value": "Anonymous", "tpe": {"type": "text"}}
}
Case — conditional logic
{
"type": "case",
"branches": [
[
{"type": "binary_expr", "left": {"type": "col_ref", "source": {"...users source..."}, "name": "status", "tpe": {"type": "text"}}, "op": "eq", "right": {"type": "literal", "value": "active", "tpe": {"type": "text"}}, "tpe": {"type": "bool"}},
{"type": "literal", "value": "yes", "tpe": {"type": "text"}}
]
],
"default": {"type": "literal", "value": "no", "tpe": {"type": "text"}}
}
Each branch is a [predicate, result] pair. The default is required.
ExistsExpr / InValues / InSubquery
{"type": "exists_expr", "subquery": { "...source..." }}
{
"type": "in_values",
"expr": {"type": "col_ref", "source": {"...users source..."}, "name": "status", "tpe": {"type": "text"}},
"values": [
{"type": "literal", "value": "active", "tpe": {"type": "text"}},
{"type": "literal", "value": "pending", "tpe": {"type": "text"}}
]
}
{
"type": "in_subquery",
"expr": {"type": "col_ref", "source": {"...users source..."}, "name": "id", "tpe": {"type": "uuid"}},
"subquery": { "...source that returns exactly one column..." }
}
ScalarSubquery — single-value subquery
Embeds a full Source as a scalar value. The subquery must return exactly one column.
{
"type": "scalar_subquery",
"subquery": {
"type": "project",
"input": {
"type": "filter",
"input": { "...loans table..." },
"pred": { "...user_id = outer.id..." }
},
"mapping": {
"max_balance": {"type": "agg_expr", "func": "max", "arg": {"type": "col_ref", "..."}, "distinct": false, "tpe": {"type": "float8"}}
}
},
"tpe": {"type": "float8"}
}
Enables correlated subqueries like SELECT (SELECT max(balance) FROM loans WHERE user_id = u.id).
Let — expression-level binding (Scala DSL only)
Let binds a computed expression for reuse within a body expression. The compiler inlines it before emission — emitters never see Let nodes.
Note: Let uses Higher-Order Abstract Syntax (HOAS) internally and cannot be serialized to or deserialized from JSON. It is only available through the Scala DSL. Polyglot clients (Python, Java, TypeScript, Rust) should duplicate the expression subtree or extract the shared computation into a separate Project node.
RawExpr — raw SQL escape hatch
{"type": "raw_expr", "sql": "EXTRACT(EPOCH FROM NOW())", "tpe": {"type": "int4"}, "deps": []}
Array & JSON Operations
DBQC provides array and JSON operations that render to the correct syntax for each target dialect. These cover aggregation into arrays/JSON, element access, containment checks, and JSON construction.
Array/JSON Aggregate Functions
In addition to count, sum, avg, min, and max, two aggregate functions produce array and JSON results:
arrayAgg — aggregate column values into an array:
{
"type": "agg_expr",
"func": "array_agg",
"arg": {"type": "col_ref", "source": {"...source..."}, "name": "tag", "tpe": {"type": "text"}},
"distinct": false,
"tpe": {"type": "jsonb"},
"filter": null
}
jsonAgg — aggregate column values into a JSON array:
{
"type": "agg_expr",
"func": "json_agg",
"arg": {"type": "col_ref", "source": {"...source..."}, "name": "tag", "tpe": {"type": "text"}},
"distinct": false,
"tpe": {"type": "jsonb"},
"filter": null
}
Both support .filter for FILTER (WHERE ...) like any other aggregate.
Array/JSON Expression Operations
These are expression-level operations on array-typed or JSON-typed values.
arrayLength — element count of an array. Uses CARDINALITY as the canonical function name; each dialect rewrites it:
{
"type": "func_expr",
"name": "CARDINALITY",
"args": [{"...array expression..."}],
"tpe": {"type": "int4"}
}
arrayContains — check if an array contains a scalar value. Uses the array_contains binary operator:
{
"type": "binary_expr",
"left": {"...array expression..."},
"op": "array_contains",
"right": {"...scalar value..."},
"tpe": {"type": "bool"}
}
jsonExtractText — extract a text value from JSON by key (PG: ->>) Returns a plain string. Uses the json_extract_text binary operator:
{
"type": "binary_expr",
"left": {"...json expression..."},
"op": "json_extract_text",
"right": {"type": "literal", "value": "name", "tpe": {"type": "text"}},
"tpe": {"type": "text"}
}
jsonExtract — extract a JSON sub-value by key (PG: ->). Returns a JSON value. Uses the json_extract binary operator:
{
"type": "binary_expr",
"left": {"...json expression..."},
"op": "json_extract",
"right": {"type": "literal", "value": "address", "tpe": {"type": "text"}},
"tpe": {"type": "jsonb"}
}
jsonBuildObject — construct a JSON object from interleaved key-value pairs. Uses JSONB_BUILD_OBJECT as the canonical function name:
{
"type": "func_expr",
"name": "JSONB_BUILD_OBJECT",
"args": [
{"type": "literal", "value": "name", "tpe": {"type": "text"}},
{"type": "col_ref", "source": {"...source..."}, "name": "name", "tpe": {"type": "text"}},
{"type": "literal", "value": "email", "tpe": {"type": "text"}},
{"type": "col_ref", "source": {"...source..."}, "name": "email", "tpe": {"type": "text"}}
],
"tpe": {"type": "jsonb"}
}
Example: Aggregate Tags and Build a JSON Summary
{
"type": "aggregate",
"input": {"type": "table", "name": "posts", "heading": {"..."}, "dbSchema": "public"},
"groupBy": [{"type": "col_ref", "source": {"..."}, "name": "author_id", "tpe": {"type": "uuid"}}],
"aggregates": {
"author_id": {"type": "col_ref", "source": {"..."}, "name": "author_id", "tpe": {"type": "uuid"}},
"all_tags": {"type": "agg_expr", "func": "array_agg", "arg": {"type": "col_ref", "source": {"..."}, "name": "tag", "tpe": {"type": "text"}}, "distinct": false, "tpe": {"type": "jsonb"}, "filter": null},
"post_count": {"type": "agg_expr", "func": "count", "arg": null, "distinct": false, "tpe": {"type": "int8"}, "filter": null}
},
"having": null
}
PostgreSQL output:
SELECT "posts"."author_id",
ARRAY_AGG("posts"."tag") AS "all_tags",
COUNT(*) AS "post_count"
FROM "posts"
GROUP BY "posts"."author_id"
MySQL output (same query tree):
SELECT `posts`.`author_id`,
JSON_ARRAYAGG(`posts`.`tag`) AS `all_tags`,
COUNT(*) AS `post_count`
FROM `posts`
GROUP BY `posts`.`author_id`
Errors
Errors include path breadcrumbs and fuzzy column suggestions:
Filter.input > Join.on: column 'user_id' not found (did you mean: user_uuid, user_name?)
When validation fails, query is null and errors contains human-readable messages:
{
"query": null,
"errors": [
"column 'nonexistent_col' not found",
"type mismatch on 'age': expected int4, got text",
"'= NULL' is always NULL in SQL (three-valued logic), never true or false — use IS NULL or IS NOT NULL"
],
"warnings": [
"cartesian join (no join predicate): 'users' × 'orders' — no join predicate, produces a cross product of all rows; add an ON condition"
]
}
Warnings appear alongside errors so you can fix everything in one pass.
Error types:
| Error | Meaning |
|---|---|
| Column not found | ColRef references a column not in the source's schema |
| Type mismatch | ColRef type doesn't match the schema's declared type |
| Schema mismatch | Set operation (UNION, INTERSECT, EXCEPT) sides have different schemas |
| Invalid subquery | IN / scalar subquery returns wrong number of columns |
| Missing parameter | Parameter referenced but not bound |
| Null comparison | = NULL or != NULL used — always NULL in SQL; use IS NULL / IS NOT NULL |
| Aggregate in WHERE | Aggregate function (e.g. COUNT(*)) in WHERE — move to HAVING clause |
| Window in WHERE | Window function (e.g. ROW_NUMBER()) in WHERE — wrap in a subquery |
| Ungrouped column | Column in SELECT not in GROUP BY and not aggregated — MySQL silently picks random row |
| Empty column name | Empty string as a column name — every column must have a non-empty name |
| Invalid column name | Null byte or control character in column name — silent truncation or driver crash |
| Column collision | Ambiguous column exposed by multiple sources in a join — rename with an alias |
Warnings
Warnings are non-fatal diagnostics surfaced alongside both successful and failed compilations. They flag patterns that compile but are almost certainly wrong.
{
"query": {"sql": "SELECT ...", "paramOrder": [], "rowSchema": [...]},
"errors": [],
"warnings": [
"ORDER BY in subquery has no effect: ORDER BY inside a subquery is ignored by most databases — move it to the outer query"
]
}
Warning types:
| Warning | Meaning |
|---|---|
| Always-true predicate | Both sides of = are identical (e.g. col = col) — always true |
| Always-false predicate | Both sides of != are identical — always false (or NULL) |
| Cartesian join | JOIN with no predicate — produces a cross product of all rows |
| ORDER BY in subquery | ORDER BY inside a subquery is stripped by most databases |
| LIKE without wildcard | LIKE pattern has no % or _ — equivalent to = with worse performance |
| Empty IN list | IN() with zero values — syntax error on most engines, always false on the rest |
| Contradictory predicates | col = 'a' AND col = 'b' in the same conjunction — always produces zero rows |
| Redundant DISTINCT | Nested DISTINCT — the inner already deduplicates, outer is wasted CPU |
| Write-read conflict | DML reads from the same table it writes to — execution order is undefined |
| Unused join source | Joined table whose columns are never referenced — likely a leftover from refactor |
| Identifier too long | Column name exceeds dialect limit (PG: 63, MySQL: 64, Oracle 12c: 30) — silently truncated or rejected |
Composability
Queries are trees. Any subtree can be extracted, named, and reused across multiple queries.
For example, define an "active users" fragment once:
{
"type": "filter",
"input": {
"type": "table",
"name": "users",
"dbSchema": "public",
"heading": [
{"name": "id", "type": "uuid"},
{"name": "name", "type": "text"},
{"name": "status", "type": "text"}
]
},
"pred": {
"type": "binary_expr",
"left": {"type": "col_ref", "source": {"...users table..."}, "name": "status", "tpe": {"type": "text"}},
"op": "eq",
"right": {"type": "literal", "value": "active", "tpe": {"type": "text"}},
"tpe": {"type": "bool"}
}
}
Then use it as the input of any other node — a join, an aggregate, a projection. The compiler resolves the dependency graph and emits the right CTEs in the right order. You never manage CTE names or ordering.
DML operations (UPDATE, INSERT, DELETE) with RETURNING work the same way: the result of an UPDATE can be joined against or filtered by downstream nodes. The compiler topologically sorts the entire DAG including DML.