> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-55d9d317.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Allows to perform queries on data stored in a SQLite database.

# sqlite

Allows to perform queries on data stored in a [SQLite](/reference/engines/database-engines/sqlite) database.

<h2 id="syntax">
  Syntax
</h2>

```sql theme={null}
sqlite('db_path', 'table_name')
```

<h2 id="arguments">
  Arguments
</h2>

* `db_path` — Path to a file with an SQLite database. [String](/reference/data-types/string).
* `table_name` — Name of a table in the SQLite database, or a query passed to SQLite as is (see [Passing a query instead of a table name](#passing-a-query)). [String](/reference/data-types/string).

<h2 id="returned_value">
  Returned value
</h2>

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

<h2 id="passing-a-query">
  Passing a query instead of a table name
</h2>

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:

```sql theme={null}
SELECT * FROM sqlite('sqlite.db', (SELECT col1, col2 FROM table1 WHERE col2 > 1));
SELECT * FROM sqlite('sqlite.db', query('SELECT col1, col2 FROM table1 WHERE col2 > 1'));
```

Such a table is read-only: `INSERT` into it is not allowed. The same syntax is supported by the [`SQLite`](/reference/engines/table-engines/integrations/sqlite) table engine.

<Note>
  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`](/reference/settings/session-settings#external_table_strict_query) an outer filter that cannot be pushed down is rejected with an exception instead of being applied locally.
</Note>

<h2 id="example">
  Example
</h2>

```sql title="Query" theme={null}
SELECT * FROM sqlite('sqlite.db', 'table1') ORDER BY col2;
```

```text title="Response" theme={null}
┌─col1──┬─col2─┐
│ line1 │    1 │
│ line2 │    2 │
│ line3 │    3 │
└───────┴──────┘
```

<h2 id="related">
  Related
</h2>

* [SQLite](/reference/engines/table-engines/integrations/sqlite) table engine
* [SQLite database engine](/reference/engines/database-engines/sqlite) — Data types support section
