Query grammar#
Query grammar describes SQL-like select, insert, update, delete, save, merge, joins, grouping, ordering, and DDL statements.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/query.g4 |
| Grammar name | query |
| Grammar kind | parser |
| Imports | common, expression, literal, type |
| Imported by | function |
| Direct rule or token count | 100 |
How to use this page#
Read the examples first when authoring Business Language. Use the rule inventory when checking exact grammar coverage or when updating parser, lowering, editor, or documentation behavior.
Entry rules and syntax families#
Start with these rules when reading this grammar: queryDeclaration, enhancedSelectStatement, selectClause, selectVarClause, guardedSelectExpression, selectExpression, fromClause, joinedTableExpression, tableExpression, coreTableExpression.
- Declarations:
queryDeclaration - Statements:
cteStatement,deleteStatement,enhancedSelectStatement,insertStatement,mergeStatement,saveStatement,unionStatement,updateStatement, and 1 more - Expressions:
betweenExpression,coreTableExpression,errorCheckExpression,existsExpression,guardedSelectExpression,havingExpression,inExpression,joinedTableExpression, and 13 more - Clauses:
controllerClause,cubeClause,filterClause,forUpdateClause,fromClause,groupByClause,groupingSetsClause,havingClause, and 15 more - Types:
joinType - Bodies:
cteBody,tableParenBody
Key grammar excerpts#
queryDeclaration#
queryDeclaration: unionStatement
| saveStatement
| insertStatement
| updateStatement
| deleteStatement
| mergeStatement
| cteStatement
;enhancedSelectStatement#
enhancedSelectStatement
: SELECT selectClause
fromClause?
whereClause?
groupByClause?
havingClause?
orderByClause?
limitClause?
offsetClause?
(limiterClause | controllerClause)?
forUpdateClause?
// @role(ambient_member_scope)
;selectClause#
selectClause
: selectVarClause
| selectItemList
;Complete rule and token inventory#
aggregateArgList, aggregateArgs, aggregateFunction, aggregateFunctionName, betweenExpression, controllerClause, coreTableExpression, cteBody
cteDefinition, cteDefinitionList, cteRecursive, cteStatement, cubeClause, deleteStatement, enhancedSelectStatement, errorCheckExpression
existsExpression, filterClause, forUpdateClause, fromClause, groupByClause, groupingElement, groupingSet, groupingSetsClause
guardedSelectExpression, havingClause, havingExpression, inExpression, insertSource, insertStatement, joinClause, joinCondition
joinedTableExpression, joinType, likeExpression, limitClause, limiterClause, literalList, mergeActions, mergeAlias
mergeCondition, mergeMatchedAction, mergeNotMatchedAction, mergeSource, mergeStatement, mergeTarget, nullCheckExpression, nullsOrdering
objectConstructionExpression, objectProperty, objectPropertyList, objectPropertySeparator, offsetClause, onConflictClause, orderByClause, orderByExpression
orderByItem, orderByItemList, orderByItemSuffix, orderByLimitOffset, orderDirection, overClause, partitionExpression, queryDeclaration
querySubquery, returningClause, returningItem, rollupClause, saveStatement, selectClause, selectExpression, selectItem
selectItemList, selectVarClause, tableAlias, tableExpression, tableParenBody, unionOperator, unionStatement, updateAssignment
updateAssignmentList, updateExpression, updateStatement, valueExpression, valuesClause, valuesList, whenMatchedClause, whenNotMatchedClause
whereAndExpression, whereClause, whereExpression, whereOrExpression, wherePrimaryExpression, windowArgs, windowFunction, windowFunctionName
windowSpecGroup, windowSpecification, windowSpecToken, withStatementExamples#
Select query#
select var invoice: Invoice
where Invoice.vendor_id = vendor_id
order by Invoice.invoice_date desc;Update query#
let policy = require_posting_policy(company_code_param, document_type_param, today());
update Invoice
set status = policy.posted_status
where Invoice.invoice_id = invoice_id;Insert with returning#
insert into VendorAudit (vendor_id, company_code, event_name)
values (vendor_id_param, company_code_param, "vendor.created")
returning vendor_id;Merge from a source table#
merge into VendorSearch
using Vendor on VendorSearch.vendor_id = Vendor.vendor_id
when matched then update set display_name = Vendor.vendor_name
when not matched then insert (vendor_id, display_name) values (Vendor.vendor_id, Vendor.vendor_name);Common authoring mistakes#
- Do not use query syntax to bypass required configuration resolution.
- Keep DML conditions explicit; broad updates and deletes should be guarded by typed parameters or prior validation.
Related guides#
- /language/queries-dml/
- /language/functions-services/
Authoring notes#
- Keep examples aligned with the grammar source, not with inferred syntax from another language.
- Use declared messages for user-facing failures, and fail closed when required configuration is absent.