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

# Natural Language Postgres CLI

> Query PostgreSQL from the command line

Query PostgreSQL databases using natural language from the command line.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    User([User]) --> CLI[CLI]
    CLI --> DB[(Postgres)]

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff

    class DB agent
    class User,CLI tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

```

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    User([User]) --> CLI[CLI]
    CLI --> DB[(Postgres)]

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff

    class DB agent
    class User,CLI tool
```

## Quick Start

**1. Simple Usage**

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai-ts postgres query "Show all users" \
  --connection-url $DATABASE_URL
```

**2. With Configuration**

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai-ts postgres query "Top 10 products by sales" \
  --connection-url $DATABASE_URL \
  --max-rows 10 \
  --json
```

## Commands

### Query Database

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Simple query
praisonai-ts postgres query "Show all users" \
  --connection-url $DATABASE_URL

# With options
praisonai-ts postgres query "Top 10 products by sales" \
  --connection-url $DATABASE_URL \
  --max-rows 10 \
  --json
```

### Show Schema

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# List all tables
praisonai-ts postgres schema \
  --connection-url $DATABASE_URL

# Show specific table
praisonai-ts postgres schema users \
  --connection-url $DATABASE_URL
```

### Interactive Mode

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Start interactive SQL chat
praisonai-ts postgres chat \
  --connection-url $DATABASE_URL \
  --read-only
```

## Options

| Option | Type | Default | Description |
| - | - | - | - |
| `--connection-url` | string | env | Database URL |
| `--read-only` | boolean | `true` | Read-only mode |
| `--max-rows` | number | `100` | Max rows returned |
| `--allowed-tables` | string | - | Comma-separated whitelist |
| `--blocked-tables` | string | - | Comma-separated blacklist |
| `--json` | boolean | `false` | JSON output |
| `--show-sql` | boolean | `false` | Show generated SQL |

## Examples

### Basic Queries

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# List users
praisonai-ts postgres query "Show all active users"

# Aggregation
praisonai-ts postgres query "Average order value by month"

# With SQL output
praisonai-ts postgres query "Top customers" --show-sql
```

### Restricted Access

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Only allow specific tables
praisonai-ts postgres query "Show products" \
  --allowed-tables products,categories

# Block sensitive tables
praisonai-ts postgres query "Show data" \
  --blocked-tables users,payments
```

## Environment Variables

| Variable | Required | Description |
| - | - | - |
| `DATABASE_URL` | Yes | PostgreSQL connection URL |
| `OPENAI_API_KEY` | Yes | For NL to SQL |

## Related

> [card] [Natural Language Postgres](https://praison.ai/docs/js/nl-postgres.md)
>
> SDK usage

> [card] [PostgreSQL](https://praison.ai/docs/js/postgres.md)
>
> Agent persistence


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.