---
sidebar_position: 2
title: "2 - Loading Your Data"
sidebar_label: "2 - Loading Data"
description: "Learn how to load your own datasets into MotherDuck"
sql_editor: true
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import MotherDuckSQLEditor from '@site/src/components/MotherDuckSQLEditor';

In this section, you'll learn how to load your own data into MotherDuck and run powerful hybrid queries that combine local and cloud data.

👈 **[Go back to Part 1: Running Your First Query](../part-1)**

## Loading your data

### Loading data using CREATE TABLE AS SELECT

The `CREATE TABLE AS SELECT` (CTAS) pattern creates a new table and populates it with data in a single operation:

```sql
CREATE OR REPLACE TABLE docs_playground.my_table AS SELECT * FROM 'my_data.csv';
```

### Loading data using INSERT INTO

The `INSERT INTO` pattern lets you append data to existing tables, update specific records, and manage data incrementally:

```sql
-- First, create the table structure
CREATE TABLE docs_playground.my_table AS SELECT * FROM 'my_data.csv' LIMIT 0;

-- Then load data incrementally
INSERT INTO docs_playground.my_table SELECT * FROM 'new_data.csv';
INSERT OR REPLACE INTO docs_playground.my_table SELECT * FROM 'updated_data.csv';
```

:::tip
While `CREATE TABLE AS SELECT` is convenient for one-time loads or small datasets, for larger datasets and production workflows, we recommend using `INSERT INTO`. This approach provides better control over data loading, allows for incremental updates, and is more efficient for ongoing data management.
:::

There are several ways to get your data into MotherDuck, depending on where your data lives:

### From local file system

To load data files from your file system into MotherDuck, you'll need:

1. A valid MotherDuck token stored as the `motherduck_token` environment variable
2. A DuckDB client (DuckDB CLI, Python, etc.)

To create a MotherDuck token, navigate to the MotherDuck UI, click your organization name in the top left, then go to **Settings > Integrations > Access Token**. For detailed instructions, see our [authentication guide](../../key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/authenticating-to-motherduck.md).



<Tabs>
<TabItem value="cli" label="DuckDB CLI">

Install the DuckDB CLI for macOS/Linux. For other operating systems, see the [DuckDB installation guide](https://duckdb.org/docs/installation/).

```bash
curl -s https://install.motherduck.com | sh
```

Launch the DuckDB CLI:

```bash
duckdb
```

```sql
-- Connect to MotherDuck
ATTACH 'md:';

-- Load CSV data from your local file into the playground database
CREATE TABLE docs_playground.popular_currency_rate_dollar AS 
SELECT * FROM './popular_currency_rate_dollar.csv';
```

</TabItem>
<TabItem value="python" label="Python">

Install DuckDB using your preferred package manager, such as pip:

```bash
pip install duckdb
```

```python
import duckdb

# Connect to MotherDuck
conn = duckdb.connect('md:')

# Load data into the playground database (automatically created)
conn.execute("""
    CREATE TABLE docs_playground.popular_currency_rate_dollar AS 
    SELECT * FROM './popular_currency_rate_dollar.csv'
""")
```

</TabItem>
<TabItem value="mdui" label="MotherDuck UI">

Head over to the `Add data` button in the MotherDuck UI and upload your file directly. This works great for smaller files and provides a visual interface.

![Add file](./img/screenshot_add_data.png)

![load data](./img/screenshot_loading_data2.png)

</TabItem>
</Tabs>

### From remote storage (S3, GCS, etc.)

For data already stored in cloud storage, you have multiple options:

<Tabs>
<TabItem value="sql" label="SQL">

You can run queries directly against remote storage using our interactive SQL editor:

<MotherDuckSQLEditor
  database="docs_playground"
  query="CREATE TABLE IF NOT EXISTS docs_playground.popular_currency_rate_dollar AS SELECT * FROM 's3://us-prd-motherduck-open-datasets/misc/csv/popular_currency_rate_dollar.csv';" />

</TabItem>
<TabItem value="cli" label="DuckDB CLI">

```sql
ATTACH 'md:';
CREATE TABLE docs_playground.popular_currency_rate_dollar AS 
SELECT * FROM 's3://us-prd-motherduck-open-datasets/misc/csv/popular_currency_rate_dollar.csv';
```

</TabItem>
<TabItem value="python" label="Python">

```python
import duckdb
conn = duckdb.connect('md:')
conn.execute("""
    CREATE TABLE docs_playground.popular_currency_rate_dollar AS 
    SELECT * FROM 's3://your-bucket/your-file.csv'
""")
```

</TabItem>
<TabItem value="mdui" label="MotherDuck UI">

1. In the left panel of the UI, click **Add data**
2. Select **From cloud storage**
3. For a publicly accessible bucket, skip creating a secret
4. Switch to **Wildcard** mode, and enter the S3 path `s3://us-prd-motherduck-open-datasets/**/popular_currency_rate_dollar.csv`
5. Name the table `popular_currency_rate_dollar` and select `docs_playground` as the destination database
6. Click **Create table**

![Create table from S3](./img/screenshot_ui_create_table_from_s3.png)

For more details, see [Loading Data from Cloud Storage](../../key-tasks/loading-data-into-motherduck/loading-data-from-cloud-or-https.md).

</TabItem>
</Tabs>

:::info
For private AWS s3 buckets, you'll need to configure AWS credentials. Check our [AWS s3 authentication guide](../../integrations/cloud-storage/amazon-s3.mdx) for details.
:::

### Querying your data

Once your data is loaded, you can query it from any interface:

<Tabs>
<TabItem value="sql" label="SQL">

<MotherDuckSQLEditor
  database="docs_playground"
  query="FROM docs_playground.popular_currency_rate_dollar LIMIT 10;" />

</TabItem>
<TabItem value="cli" label="DuckDB CLI">

```sql
ATTACH 'md:';
FROM docs_playground.popular_currency_rate_dollar LIMIT 10;
```

</TabItem>
<TabItem value="python" label="Python">

```python
import duckdb

# Connect to MotherDuck
conn = duckdb.connect('md:')

# Query your data
result = conn.sql("FROM docs_playground.popular_currency_rate_dollar LIMIT 10").fetchall()
print(result)
```

</TabItem>
</Tabs>

👉 **[Continue to Part 3: Sharing Your Database →](../part-3)**
