# Replicating flat files to MotherDuck


> Load CSV, Parquet, and JSON files into MotherDuck from local storage or cloud sources.

The goal of this guide is to show users simple examples of loading data from flat file sources into MotherDuck. Examples are shown for both the MotherDuck Web UI and the DuckDB CLI. To install the DuckDB CLI, [check out the instructions first.](/getting-started/interfaces/connect-query-from-duckdb-cli)

## CSV

### MotherDuck UI

From the UI, follow these steps:

1. Navigate to the **Add Data** section.
2. Select the file. This file will be uploaded into your browser so that it can be queried by DuckDB.
3. Execute the generated query which will create a table for you.
   1. Modify the query as needed to suit the correct Database / Schema / Table name.

### DuckDB CLI

In the CLI, you can load a CSV file using the `read_csv` function. For example:

### Local file

```sql
CREATE TABLE my_table AS
SELECT * FROM read_csv('path/to/local_file.csv');
```

### S3 file
To load from S3, ensure your DuckDB instance is configured with [S3 secrets](/documentation/integrations/cloud-storage/amazon-s3.mdx). Then:

```sql
CREATE TABLE my_table AS
SELECT * FROM read_csv('s3://bucket-name/path-to-file.csv');
```

## JSON

### MotherDuck UI

From the UI, follow these steps:

1. Navigate to the **Add Data** section.
2. Select the file. This file will be uploaded into your browser so that it can be queried by DuckDB.
3. Execute the generated query which will create a table for you.
   1. Modify the query as needed to suit the correct Database / Schema / Table name.

### DuckDB CLI

In the CLI, use the `read_json` function to load JSON files.

### Local file

```sql
CREATE TABLE my_table AS
SELECT * FROM read_json('path/to/local_file.json');
```

### S3 file
Make sure S3 support is enabled as described in the [S3 secrets documentation](/documentation/integrations/cloud-storage/amazon-s3.mdx).

```sql
CREATE TABLE my_table AS
SELECT * FROM read_json('s3://bucket-name/path-to-file.json');
```

:::tip Provide a schema for large or deeply nested JSON
When loading large JSON files, DuckDB scans the data to discover the schema during query planning. For deeply nested or complex JSON, this can add significant time.

To speed things up, provide the schema directly with the `columns` parameter:

```sql
CREATE TABLE my_table AS
SELECT * FROM read_json(
  'path/to/local_file.json',
  columns={
    id: 'BIGINT',
    name: 'VARCHAR',
    amount: 'DECIMAL(10,2)'
  }
);
```

If you already have a table with the right schema, use `INSERT INTO` instead of `CREATE TABLE AS` — DuckDB skips schema discovery when the target schema is known:

```sql
INSERT INTO my_table
SELECT * FROM read_json('path/to/local_file.json');
```

You can also limit how deep DuckDB looks into nested structures with `maximum_depth`, or reduce the number of sampled objects with `sample_size` (default: 20480). See the [DuckDB JSON documentation](https://duckdb.org/docs/stable/data/json/loading_json) for all available options.
:::

## Parquet

### MotherDuck UI

From the UI, follow these steps:

1. Navigate to the **Add Data** section.
2. Select the file. This file will be uploaded into your browser so that it can be queried by DuckDB.
3. Execute the generated query which will create a table for you.
   1. Modify the query as needed to suit the correct Database / Schema / Table name.

### DuckDB CLI

In the CLI, use the `read_parquet` function to load Parquet files.

### Local file

```sql
CREATE TABLE my_table AS
SELECT * FROM read_parquet('path/to/local_file.parquet');
```

### S3 file
Ensure S3 support is enabled as described in the [S3 secrets documentation](/documentation/integrations/cloud-storage/amazon-s3.mdx).

```sql
CREATE TABLE my_table AS
SELECT * FROM read_parquet('s3://bucket-name/path-to-file.parquet');
```

## Handling more complex workflows

Production use cases tend to be much more complex and include things like incremental builds & state management. In those scenarios, please take a look at our [ingestion partners](https://motherduck.com/ecosystem/?category=Ingestion), which includes many options including some that offer native python. An overview of the MotherDuck Ecosystem is shown below.

![Diagram](../../../img/md-diagram.svg)


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `POST https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

Payload:

```json
{
  "page_path": "/key-tasks/data-warehousing/replication/flat-files/",
  "page_title": "Flat Files",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed payloads, and `429` when rate-limited.
