Syntax overview
BtrQL source is a file of headers, symbols definitions and top level queries and procedure calls.
Syntax failures and migration guidance are reported through Diagnostics and errors.
Grammar
This grammar map is compact, not the full formal grammar. The extension-column surface below is currently implemented by the PostgreSQL and ClickHouse C# prototypes.
file ::= header* item*header ::= using_header | schema_header | import_headerusing_header ::= "using" schema_nameschema_header ::= "schema" schema_nameimport_header ::= "import" module_path [ "{" import_alias ("," import_alias)* "}" ]import_alias ::= ident [ "->" ident ]item ::= query | dml | call_stmt | object_decl | reusable_decl | routine_decl | macro_declreusable_decl ::= "val" ident "=" expr | "type" ident "=" type_expr | extension_declextension_decl ::= "extension" table_type "{" extension_member* "}"extension_member ::= method_decl | column_declmethod_decl ::= "method" ident [ table_param_group ] [ scalar_param_group ] [ "=>" table_type ] "=" relationcolumn_decl ::= "column" ident [ ":" scalar_type ] "=" exprtable_param_group ::= "(" ident ":" table_type ("," ident ":" table_type)* ")"scalar_param_group ::= "(" ident ":" scalar_type ("," ident ":" scalar_type)* ")"object_decl ::= "table" ident table_shape | "view" ident "=" relation | "materialized view" ident "=" relation | [ "unique" ] "index" ident "on" ident "(" expr_list ")" [ "where" expr ]routine_decl ::= "function" ident "(" param_list? ")" "=" expr | "table function" ident "(" param_list? ")" "=>" table_shape "=" relation | "procedure" ident "(" param_list? ")" "{" proc_stmt* "}"query ::= relationrelation ::= relation_source relation_step*relation_source ::= ident | qualified_ident | "(" relation ")" | row_literal | table_literalrelation_step ::= ".as(" ident ")" | ".select(" projection_list ")" | ".where(" expr ")" | ".addColumn(" projection_list ")" | ".removeColumn(" column_list ")" | ".orderBy(" sort_list ")" | ".limit(" expr ")" | ".offset(" expr ")" | ".distinct" | ".distinctOn(" expr_list ")" | ".group { by(" expr_list ") aggregate(" projection_list ")" [ " having(" expr ")" ] " }" | join_step | apply_step | set_step | qualify_stepprojection_list ::= projection ("," projection)*projection ::= expr [ "->" ident ]join_step ::= "." join_name "(" relation " on " expr ")"apply_step ::= ".crossApply(" relation ")" | ".outerApply(" relation ")"set_step ::= "." set_name "(" relation ")"qualify_step ::= ".qualify(" expr ")"dml ::= relation ".insert(" ident ")" | relation ".update { into " ident " set(" assignment_list ") }" | relation ".delete" | relation ".mergeInto(" ident ") { ... }" | dml ".returning(" projection_list ")"expr ::= literal | ident | qualified_ident | function_call | unary_expr | binary_expr | case_expr | window_expr | "(" expr ")"
column recipe and addColumn[Type] are removed from the C# prototype grammar and receive targeted migration diagnostics. A bare extension-column request is an ordinary scalar expression whose output alias is the extension member name. Earlier aliases in the same select or addColumn are visible only to later projections.
Top-level statements
Statements that set context, import modules, or call procedures.
Top-level statements
Loading Top-level statements...
Reusable abstractions
Names, relation types, extension methods, extension columns, and macros for reuse.
Reusable abstractions
Loading Reusable abstractions...
Schema objects
Tables, views, materialized views, and indexes.
Schema objects
Loading Schema objects...
Query pipeline
Relation-first queries, filters, ordering, limits, and expressions.
Query pipeline
Loading Query pipeline...
Projection shaping
Aliases, distinct rows, and column-shape changes.
Projection shaping
Loading Projection shaping...
Set operations
Union, intersect, and except composition.
Set operations
Loading Set operations...
Grouping and HAVING
Grouping columns, aggregate expressions, and HAVING.
Grouping and HAVING
Loading Grouping and HAVING...
Joins and APPLY
Joins and dependent relation steps.
Joins and APPLY
Loading Joins and APPLY...
CTEs and analytics
CTEs, window expressions, and post-window filters.
CTEs and analytics
Loading CTEs and analytics...
JSON and table functions
JSON helpers, table-function sources, and search/planner helpers.
JSON and table functions
Loading JSON and table functions...
Mutations and RETURNING
Insert, update, delete, merge, and returned row images.
Mutations and RETURNING
Loading Mutations and RETURNING...
Types and constraints
Declared types, table shapes, and constraints.
Types and constraints
Loading Types and constraints...
Routine definitions
Functions, table functions, procedures, and procedure bodies.
Routine definitions
Loading Routine definitions...
Builtin functions
Recognized function families for dialect-aware SQL generation.
Builtin functions
Loading Builtin functions...
Walkthroughs
Applied BtrQL-to-SQL examples that combine multiple syntax elements.
Walkthroughs
Loading Walkthroughs...
Errors
Parse, name, type, and dialect errors before SQL is emitted.
Errors
Loading Errors...
PostgreSQL Dialect
PostgreSQL is the broadest current target for BtrQL examples, generated SQL checks, and real database execution.
PostgreSQL Dialect
Loading PostgreSQL Dialect...
ClickHouse syntax
ClickHouse-specific BtrQL forms.
ClickHouse syntax
Loading ClickHouse syntax...