An AI-powered tool that can be called from inside psql to ask natural language questions about your PostgreSQL database with access to the database context and PostgreSQL documentation.
Project description
psql-chat - Natives NL-to-SQL
PostgreSQL has been one of the most popular open source databases for years. However, learning how to query data with SQL is a hurdle for many users. The AI tool “psql-chat” makes it possible to ask the database questions in natural language. The chatbot then suggests an SQL query or a psql command. After approval, the command can be executed or the prompt can be adjusted.
This makes database administrators more efficient, while users can perform data analyses without in-depth SQL knowledge
Quick Start
Windows
- Run setup:
.\setup.ps1 - Set API key:
$env:OPENAI_API_KEY = "your-key" - Configure pgpass: (optional but recommended) Add the connection details to your
pgpassfile for passwordless access. - Use from psql:
\! psql-chat "show me all tables"
Usage
From psql (recommended):
\! psql-chat "find users who haven't logged in recently"
\! psql-chat "count orders by month" -e -- execute immediately (after confirmation)
\! psql-chat "explain JSONB indexing strategies" -- gets docs automatically
Note: These usage examples assume psql-chat is in your PATH. This is done automatically by the setup script. Otherwise use uvx psql-chat ... after installation.
How It Works
- Converts natural language to PostgreSQL commands
- Analyzes database schema for context
- Fetches PostgreSQL docs automatically when needed
- Shows syntax-highlighted SQL with explanation
- Optional execution with safety warnings
Features
- Smart context - Uses your database schema
- Auto documentation - Fetches PostgreSQL docs via Context7
- Safety first - Warns before data modifications
- Rich formatting - Syntax highlighting and explanations
- Flexible modes - Explain-only (default) or execute with
--execute - Fast option - Skip docs with
--no-docs
Options
--execute, -e- Execute the command (default: explain only)--dsn- Database connection string--no-context- Skip database schema gathering--no-docs- Skip PostgreSQL documentation--version, -v- Show version
Requirements
- OpenAI API key (set
OPENAI_API_KEY) - PostgreSQL connection (via psql environment or
--dsn) - uv package manager (auto-installed by setup script)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file psql_chat-0.3.0.tar.gz.
File metadata
- Download URL: psql_chat-0.3.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3ef9baf26d2368de2de95bd86be234a5f0a0b998df6b504fd67ffea6c99acdf
|
|
| MD5 |
acaa68b0f6f6398b7e239f96efc0da65
|
|
| BLAKE2b-256 |
236beaf8e896dfab14aa40ee25543aa65a9c26c42f81631f52777a0b2bdf7da6
|
File details
Details for the file psql_chat-0.3.0-py3-none-any.whl.
File metadata
- Download URL: psql_chat-0.3.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
058d87431157f190a72277bcf83cface42c943b8692372929e1a73c308cadd0f
|
|
| MD5 |
88ddd57ff9e61aaefbf1730832c80627
|
|
| BLAKE2b-256 |
7ee32a0a9cad54dee4361d256deab48cbd80b3cf04e0d19160a0cbeaa36d59b5
|