> ## Documentation Index
> Fetch the complete documentation index at: https://planetscale.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PlanetScale CLI commands: query-patterns

## Getting Started

Make sure to first [set up your PlanetScale developer environment](/cli/planetscale-environment-setup). Once you've installed the `pscale` CLI, you can interact with PlanetScale and manage your databases straight from the command line.

## The `query-patterns` command

Download a CSV report of the query patterns for a database branch. The command creates a Query
Insights report, waits for the report to finish generating, and writes the CSV file locally.

Query pattern reports require Query Insights to be enabled for the database.

**Usage:**

```bash theme={null}
pscale branch query-patterns download <database> <branch> --org <org> <FLAG>
```

### Available sub-commands

| **Sub-command** | **Product**      | **Description**                                             |
| :-------------- | :--------------- | :---------------------------------------------------------- |
| `download`      | Postgres, Vitess | Generate and download a CSV report of branch query patterns |

### Available flags

| **Flag**                  | **Description**                                                                                                                           |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `--output <path>`         | Output file for the CSV report. Defaults to `query-patterns-<organization>-<database>-<branch>-<timestamp>.csv` in the current directory. |
| `--org <org>`             | Organization name                                                                                                                         |
| `-f`, `--format <FORMAT>` | Show the download result in a specific format. Possible values: `human` (default), `json`, `csv`.                                         |
| `-h`, `--help`            | Help for `query-patterns`                                                                                                                 |

## Examples

Download a report with the default file name:

```bash theme={null}
pscale branch query-patterns download <database> <branch> --org <org>
```

Download a report to a specific path:

```bash theme={null}
pscale branch query-patterns download <database> <branch> --org <org> --output ./query-patterns.csv
```

Use JSON output for automation:

```bash theme={null}
pscale branch query-patterns download <database> <branch> --org <org> --format json
```

The JSON response includes the report ID, final state, and local file path:

```json theme={null}
{
  "id": "report1",
  "state": "completed",
  "file": "./query-patterns.csv"
}
```

If the branch is not found, or Query Insights is not enabled for the database, the command returns an
error explaining both possible causes.

## Need help?

Get help from [the PlanetScale Support team](https://planetscale.com/contact?initial=support), or join our [Discord community](https://pscale.link/community) to see how others are using PlanetScale.
