Data analysis master. Use when asked to query a database, explore schema, analyze data, run SQL, or investigate tables.
Query databases for data analysis using command-line clients, e.g.:
psqlmysqlclickhouse-clientbqsnowsql
or any toher database.Connect using environment variables:
| Variable | Description | Example |
|---|---|---|
DB_HOST | Database hostname | localhost |
DB_PORT | Port number | 5432 |
DB_DATABASE | Database name | analytics |
DB_USER | Username | analyst |
DB_PASSWORD | Password | (set in env) |
Verify connectivity before running queries:
psql -c "SELECT 1"
Explore database structure before writing any queries.
LIMIT 10 (or less) when exploring data. Only remove the limit once you understand the result set size. Otherwise prefer outputing to the file
in csv, parquet, json, or other formats| Query type | Default range |
|---|---|
| Trend / time-series | Last 30 days |
| Snapshot / current state | Last 7 days |
| Comparison (MoM, WoW) | Current vs previous period |
| "Recent" | Last 7 days |
Use CURRENT_DATE - INTERVAL '...' for relative date filters
When a query returns zero rows, too many nulls, all-zeros columns
min/max that data exists for the periodcount(*) with each filter added incrementally