# Google Sheets
> Query Google Sheets from MotherDuck with CSV export URLs or the DuckDB Google Sheets community extension.
Google Sheets can be queried from MotherDuck in two ways:

- Use `read_csv()` with the Google Sheets `/export?format=csv` URL. This works well for server-side reads in MotherDuck and for views that should reflect the current sheet contents.
- Use the community [`duckdb-gsheets`](https://duckdb-gsheets.com/) extension when you need its Google Sheets-specific features.

## Query a sheet with read_csv()

For a public Google Sheet, use the CSV export URL:

```sql
SELECT *
FROM read_csv(
    'https://docs.google.com/spreadsheets/d/<sheet_id>/export?format=csv&gid=<tab_id>',
    MD_RUN = REMOTE
);
```

The `sheet_id` is the value between `/d/` and `/edit` in the Google Sheet URL. The `gid` identifies the worksheet tab.

When connected to MotherDuck, `read_csv()` can read the HTTPS URL server side. `MD_RUN = REMOTE` makes the execution location explicit, although non-local HTTPS reads are remote by default.

## Create a view or table

Create a view when you want queries to reflect the current Google Sheet contents:

```sql
CREATE OR REPLACE VIEW my_database.main.google_sheet AS
SELECT *
FROM read_csv(
    'https://docs.google.com/spreadsheets/d/<sheet_id>/export?format=csv&gid=<tab_id>',
    MD_RUN = REMOTE
);
```

Create a table when you want to snapshot the sheet into MotherDuck:

```sql
CREATE OR REPLACE TABLE my_database.main.google_sheet_snapshot AS
SELECT *
FROM read_csv(
    'https://docs.google.com/spreadsheets/d/<sheet_id>/export?format=csv&gid=<tab_id>',
    MD_RUN = REMOTE
);
```

## Authenticate to a private sheet

For private sheets, create an `HTTP` secret with an OAuth bearer token that has access to the sheet. Store it in MotherDuck if the query needs to run server side from future sessions or scheduled jobs:

```sql
CREATE SECRET google_sheets_http IN MOTHERDUCK (
    TYPE HTTP,
    SCOPE 'https://docs.google.com',
    EXTRA_HTTP_HEADERS MAP {
        'Authorization': 'Bearer <google_oauth_access_token>'
    }
);
```

The bearer token must come from a Google identity or service account that can read the spreadsheet. See the [DuckDB HTTP authentication documentation](https://duckdb.org/docs/current/core_extensions/httpfs/https#authenticating) for additional `httpfs` authentication options.

## Use the Google Sheets extension

The community Google Sheets extension can read sheets with `read_gsheet()`:

```sql
INSTALL gsheets FROM community;
LOAD gsheets;

CREATE SECRET (TYPE gsheet);

SELECT *
FROM read_gsheet('https://docs.google.com/spreadsheets/d/<sheet_id>/edit');
```

This workflow may require browser interactivity unless you configure an API access token. See [Using Excel and Google Sheets Data in MotherDuck](/key-tasks/data-warehousing/replication/spreadsheets/) for a longer walkthrough.

## Related content

- [Swimming in Google Sheets with MotherDuck](https://motherduck.com/blog/google-sheets-motherduck/)
- [CSV integration](/integrations/file-formats/csv/)
- [MD_RUN parameter](/sql-reference/motherduck-sql-reference/md-run-parameter/)


---

## 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": "/integrations/file-formats/google-sheets/",
  "page_title": "Google Sheets",
  "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.
