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

# How to Export Data from ClickHouse to a File

> Learn various methods to export data from ClickHouse, including `INTO OUTFILE`, the File table engine, and command-line redirection.

<h2 id="using-into-outfile-clause">
  Using INTO OUTFILE Clause
</h2>

Add an [INTO OUTFILE](/reference/statements/select/into-outfile) clause to your query.

For example:

```sql theme={null}
SELECT * FROM table INTO OUTFILE 'file'
```

By default, ClickHouse uses the file extension of the filename to deteremine the output format and compression. For example, all of the rows in `nyc_taxi` will be exported to the `nyc_taxi.parquet` using the Parquet format:

```sql theme={null}
SELECT *
FROM nyc_taxi
INTO OUTFILE 'taxi_rides.parquet'
```

And the following file will be a compressed, tab-separated file:

```sql theme={null}
SELECT *
FROM nyc_taxi
INTO OUTFILE 'taxi_rides.tsv.gz'
```

If ClickHouse can not determine the format from the file extension, then the output format defaults to [TabSeparated](/reference/formats) for output data. To specify the [output format](/reference/formats), use the [FORMAT clause](/reference/statements/select/format).

For example:

```sql theme={null}
SELECT *
FROM nyc_taxi
INTO OUTFILE 'taxi_rides.txt'
FORMAT CSV
```

<h2 id="using-a-file-engine-table">
  Using the File table engine
</h2>

Another option is to use the [File](/reference/engines/table-engines/special/file) table engine, where ClickHouse uses the file to store the data. You can perform queries and inserts directly on the file.

For example:

```sql theme={null}
CREATE TABLE my_table (
   x UInt32,
   y String,
   z DateTime
)
ENGINE = File(Parquet)
```

Insert a few rows:

```sql theme={null}
INSERT INTO my_table VALUES
   (1, 'Hello', now()),
   (2, 'World', now()),
   (3, 'Goodbye', now())
```

The file is stored in the `data` folder of your ClickHouse server - specifically in `/data/default/my_table` in a file named `data.Parquet`.

<Note>
  Using the `File` table engine is incredibly handy for creating and querying files on your file system, but keep in mind that `File` tables are not `MergeTree` tables, so you don't get all the benefits that come with `MergeTree`. Use `File` for convenience when exporting data out of ClickHouse in convenient formats.
</Note>

<h2 id="using-command-line-redirection">
  Using Command-Line Redirection
</h2>

```bash theme={null}
$ clickhouse-client --query "SELECT * from table" --format FormatName > result.txt
```

See [clickhouse-client](/concepts/features/interfaces/cli).
