---
name: ulk-pgcli
description: "Connect to Postgres databases using pgcli with autocompletion and syntax highlighting. Use for SQL queries, compatible with Neon via neonctl connection-string."
---

# pgcli (Postgres CLI)

## Prerequisite
Verify: `command -v pgcli`
If absent:
- macOS: `brew install pgcli`
- Linux: `pip install pgcli`

## Advantages over psql
- Autocompletion for tables, columns, keywords
- Syntax highlighting
- Smart command history
- Multi-line editing
- Output formats (csv, json, table)

## Connection
```bash
pgcli postgres://user:pass@host/db          # Direct connection string
pgcli -h localhost -d mydb -U postgres       # Host/db/user params
pgcli $(neonctl connection-string)           # Via Neon CLI
pgcli $(neonctl connection-string --branch feature-x)  # Neon branch
```

## Output Formats
```bash
# Inside pgcli:
\pset format csv       # CSV output
\pset format json      # JSON output
\pset format table     # Table output (default)
```

## Non-interactive
```bash
pgcli postgres://... -e "SELECT count(*) FROM users"
pgcli postgres://... < query.sql
```
