Comments
FQL supports comments inside query strings. Comments are ignored during parsing and can be used to annotate or temporarily disable parts of a query.#or--starts a single-line comment (everything until end of line is ignored)/* ... */encloses a multi-line comment
FileQuery syntax
TheFROM, JOIN, and INTO clauses use the FileQuery notation to reference files:
Examples:
Field path syntax
Field references use dot notation to access nested data. Advanced path features include:
Backtick escaping lets you reference keys that contain dots, spaces, or special characters. This syntax works in
SELECT, WHERE, ORDER BY, GROUP BY, ON, and function arguments.
[] paths as arguments and operate on the flattened array. For example, LENGTH(products.product[]) returns the number of elements, and IMPLODE(products.product[].name, ', ') joins every nested name into a single string. Backtick-escaped segments work the same way inside function arguments.
Prior to FiQueLa 3.0.2, scalar functions wrapping a
[] path returned null because the parser bypassed function detection whenever the field contained []. Upgrade to 3.0.2 or later to use array-iterator paths inside scalar functions.SELECT
select_expr— column name, function call, or literal. Supports dot notation for nested fields.*selects all fields and can be combined with additional expressions (SELECT *, totalPrice).AS alias— optional alias for the expression.EXCLUDE— removes the listed fields from the output. Fields excluded this way can still be used inHAVINGconditions.
Aliased wildcards
When using source aliases (fromFROM ... AS or JOIN ... AS), you can select all fields from a specific aliased source using alias.*:
alias.* for both, a SelectException is thrown on ambiguous field conflicts.
Examples:
Literal values
You can use quoted literal values directly inSELECT. Literal strings are automatically cast to their appropriate type:
You can also reference a previously aliased field in a later expression within the same
SELECT:
FROM
file_reference is a FileQuery string. The path inside the FileQuery sets the data root:
FROM an already-open stream
When you run FQL against a stream you have already opened, theFROM clause does not need a file. Write a bare * for the root of the stream (CSV rows, XLSX/ODS sheet rows, a top-level JSON array), or a data path such as SHOP.SHOPITEM:
FROM * AS t and DESCRIBE * work too. The same applies to Sql\Provider::compile($sql)->applyTo($query), which navigates the existing query to the root path.
A bare
* only names the root of an open stream. INTO * and JOIN * AS j are syntax errors, because they name no file to write to or join with. Building such a query on its own with toQuery() throws a QueryLogicException that asks for a format(path) source or applyTo(). Available since FiQueLa 3.2.6.FROM aliasing
You can alias theFROM source using AS. Aliased fields are then accessible via alias.field dot notation, which is especially useful when joining multiple sources:
alias.* in SELECT to select all fields from the aliased source.
WHERE and HAVING
WHERE filters rows before aggregation. HAVING filters after aggregation.
Examples:
GROUP BY
ORDER BY
LIMIT and OFFSET
EXPLAIN and EXPLAIN ANALYZE
PrependEXPLAIN to return a query execution plan without processing data. Use EXPLAIN ANALYZE to execute the query and collect real row counts and timings.
phase, rows_in, rows_out, filtered, time_ms, duration_pct, mem_peak_kb, note.
WITH (common table expressions)
Declare one or more named subqueries before the mainSELECT. Each CTE can be referenced by name from any FROM, JOIN, or UNION branch.
- A single
WITHkeyword declares any number of comma-separated CTEs. - Later CTEs may reference earlier ones (forward-only chaining).
- Duplicate names,
WITH RECURSIVE, and references to unknown CTE names raise aParseException. EXPLAINandEXPLAIN ANALYZEaccept a leadingWITHblock.DESCRIBEcannot be combined withWITH.
UNION and UNION ALL
UNION removes duplicate rows. UNION ALL keeps all rows. The number of selected columns must match across all queries.
INTO
Export query results to a file using the same FileQuery notation:.query path in INTO depends on the target format:
Existing target files are not overwritten — an exception is thrown if the file already exists. Missing output directories are created automatically.
DESCRIBE
UseDESCRIBE to inspect the schema of a data source. Returns one row per column with type statistics.
file_reference follows the FileQuery syntax.
DESCRIBE is a standalone statement — it cannot be combined with SELECT, WHERE, GROUP BY, ORDER BY, LIMIT, JOIN, UNION, or EXPLAIN.
Examples: