Skip to main content
Allows to perform queries on data stored in a SQLite database.

Syntax

Arguments

Returned value

  • A table object with the same columns as in the original SQLite table.

Passing a query instead of a table name

Instead of a table name, the second argument can be a SELECT query that is passed to SQLite as is. The structure of the resulting table is inferred from the query result. The query can be written either as a subquery, or wrapped into the query function:
Such a table is read-only: INSERT into it is not allowed. The same syntax is supported by the SQLite table engine.
The subquery form (SELECT ...) is parsed by ClickHouse and re-serialized before being sent to SQLite. It must therefore be valid ClickHouse SQL. To pass SQLite-specific syntax that ClickHouse does not parse, use the query('...') form, whose text is sent to SQLite verbatim.Any outer WHERE, LIMIT, aggregation, etc. of the surrounding ClickHouse query is not pushed down into the passed query — it is applied in ClickHouse after the full query result is fetched. To restrict the data read from SQLite, put the filter inside the passed query. With external_table_strict_query = 1 an outer filter on the columns of the table function is rejected with an exception instead of being applied locally, because it cannot be pushed into the passed query. The check covers the top-level WHERE predicate and each conjunct of a top-level AND. A PREWHERE on the columns of this table is not a case for this setting: this table engine do not support PREWHERE, and such a query is rejected with ILLEGAL_PREWHERE regardless of the setting. With the analyzer (the default), the check runs only where a filter could be pushed down at all: when this table is the only table of the query, on either side of an INNER JOIN, or on the preserving side of an outer join (the left side of a LEFT JOIN, the right side of a RIGHT JOIN). On the non-preserving side of a LEFT/RIGHT JOIN and on either side of a FULL JOIN nothing is pushed down and nothing is checked, so a filter on the columns of this table is applied locally after the join even in strict mode. Where the check runs, a predicate that references other tables joined in the surrounding query is not pushed down and is excluded from the check, whether it references only the joined side or mixes it with this table inside one non-AND expression (for example an OR); such a predicate keeps its usual ClickHouse evaluation point (WHERE after the join, PREWHERE before it) and is not rejected. With the old analyzer (enable_analyzer = 0) this scoping does not apply: the whole outer filter is checked when this table is the first table of the join tree, including a predicate on the joined side, and a joined right-hand table is not checked.

Example

Query
Response
Last modified on September 7, 2026