pg_ai_query
pg_ai_query
pg_ai_query : AI-powered SQL query generation for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2730 | pg_ai_query
|
pg_ai_query
|
0.1.1 |
FEAT
|
Apache-2.0
|
C++
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | pgml
pg4ml
vectorize
pg_summarize
pg_tiktoken
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.1.1 |
18
17
16
15
14
|
pg_ai_query |
- |
| RPM | PIGSTY
|
0.1.1 |
18
17
16
15
14
|
pg_ai_query_$v |
- |
| DEB | PIGSTY
|
0.1.1 |
18
17
16
15
14
|
postgresql-$v-ai-query |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
MISS
|
MISS
|
MISS
|
MISS
|
MISS
|
el8.aarch64
|
MISS
|
MISS
|
MISS
|
MISS
|
MISS
|
el9.x86_64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
el9.aarch64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
el10.x86_64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
el10.aarch64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
d12.x86_64
|
MISS
|
MISS
|
MISS
|
MISS
|
MISS
|
d12.aarch64
|
MISS
|
MISS
|
MISS
|
MISS
|
MISS
|
d13.x86_64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
d13.aarch64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
u22.x86_64
|
MISS
|
MISS
|
MISS
|
MISS
|
MISS
|
u22.aarch64
|
MISS
|
MISS
|
MISS
|
MISS
|
MISS
|
u24.x86_64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
u24.aarch64
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
PIGSTY 0.1.1
|
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_ai_query_18 |
0.1.1 |
el9.x86_64 | pigsty | 967.9 KiB | pg_ai_query_18-0.1.1-1PIGSTY.el9.x86_64.rpm |
pg_ai_query_18 |
0.1.1 |
el9.aarch64 | pigsty | 880.6 KiB | pg_ai_query_18-0.1.1-1PIGSTY.el9.aarch64.rpm |
pg_ai_query_18 |
0.1.1 |
el10.x86_64 | pigsty | 899.5 KiB | pg_ai_query_18-0.1.1-1PIGSTY.el10.x86_64.rpm |
pg_ai_query_18 |
0.1.1 |
el10.aarch64 | pigsty | 846.4 KiB | pg_ai_query_18-0.1.1-1PIGSTY.el10.aarch64.rpm |
postgresql-18-ai-query |
0.1.1 |
d13.x86_64 | pigsty | 842.3 KiB | postgresql-18-ai-query_0.1.1-1PIGSTY~trixie_amd64.deb |
postgresql-18-ai-query |
0.1.1 |
d13.aarch64 | pigsty | 760.5 KiB | postgresql-18-ai-query_0.1.1-1PIGSTY~trixie_arm64.deb |
postgresql-18-ai-query |
0.1.1 |
u24.x86_64 | pigsty | 795.0 KiB | postgresql-18-ai-query_0.1.1-1PIGSTY~noble_amd64.deb |
postgresql-18-ai-query |
0.1.1 |
u24.aarch64 | pigsty | 771.8 KiB | postgresql-18-ai-query_0.1.1-1PIGSTY~noble_arm64.deb |
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_ai_query_17 |
0.1.1 |
el9.x86_64 | pigsty | 967.8 KiB | pg_ai_query_17-0.1.1-1PIGSTY.el9.x86_64.rpm |
pg_ai_query_17 |
0.1.1 |
el9.aarch64 | pigsty | 881.9 KiB | pg_ai_query_17-0.1.1-1PIGSTY.el9.aarch64.rpm |
pg_ai_query_17 |
0.1.1 |
el10.x86_64 | pigsty | 899.4 KiB | pg_ai_query_17-0.1.1-1PIGSTY.el10.x86_64.rpm |
pg_ai_query_17 |
0.1.1 |
el10.aarch64 | pigsty | 846.4 KiB | pg_ai_query_17-0.1.1-1PIGSTY.el10.aarch64.rpm |
postgresql-17-ai-query |
0.1.1 |
d13.x86_64 | pigsty | 845.8 KiB | postgresql-17-ai-query_0.1.1-1PIGSTY~trixie_amd64.deb |
postgresql-17-ai-query |
0.1.1 |
d13.aarch64 | pigsty | 760.1 KiB | postgresql-17-ai-query_0.1.1-1PIGSTY~trixie_arm64.deb |
postgresql-17-ai-query |
0.1.1 |
u24.x86_64 | pigsty | 795.0 KiB | postgresql-17-ai-query_0.1.1-1PIGSTY~noble_amd64.deb |
postgresql-17-ai-query |
0.1.1 |
u24.aarch64 | pigsty | 771.8 KiB | postgresql-17-ai-query_0.1.1-1PIGSTY~noble_arm64.deb |
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_ai_query_16 |
0.1.1 |
el9.x86_64 | pigsty | 967.8 KiB | pg_ai_query_16-0.1.1-1PIGSTY.el9.x86_64.rpm |
pg_ai_query_16 |
0.1.1 |
el9.aarch64 | pigsty | 881.0 KiB | pg_ai_query_16-0.1.1-1PIGSTY.el9.aarch64.rpm |
pg_ai_query_16 |
0.1.1 |
el10.x86_64 | pigsty | 899.5 KiB | pg_ai_query_16-0.1.1-1PIGSTY.el10.x86_64.rpm |
pg_ai_query_16 |
0.1.1 |
el10.aarch64 | pigsty | 846.4 KiB | pg_ai_query_16-0.1.1-1PIGSTY.el10.aarch64.rpm |
postgresql-16-ai-query |
0.1.1 |
d13.x86_64 | pigsty | 841.1 KiB | postgresql-16-ai-query_0.1.1-1PIGSTY~trixie_amd64.deb |
postgresql-16-ai-query |
0.1.1 |
d13.aarch64 | pigsty | 759.0 KiB | postgresql-16-ai-query_0.1.1-1PIGSTY~trixie_arm64.deb |
postgresql-16-ai-query |
0.1.1 |
u24.x86_64 | pigsty | 795.6 KiB | postgresql-16-ai-query_0.1.1-1PIGSTY~noble_amd64.deb |
postgresql-16-ai-query |
0.1.1 |
u24.aarch64 | pigsty | 771.8 KiB | postgresql-16-ai-query_0.1.1-1PIGSTY~noble_arm64.deb |
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_ai_query_15 |
0.1.1 |
el9.x86_64 | pigsty | 967.4 KiB | pg_ai_query_15-0.1.1-1PIGSTY.el9.x86_64.rpm |
pg_ai_query_15 |
0.1.1 |
el9.aarch64 | pigsty | 881.0 KiB | pg_ai_query_15-0.1.1-1PIGSTY.el9.aarch64.rpm |
pg_ai_query_15 |
0.1.1 |
el10.x86_64 | pigsty | 899.3 KiB | pg_ai_query_15-0.1.1-1PIGSTY.el10.x86_64.rpm |
pg_ai_query_15 |
0.1.1 |
el10.aarch64 | pigsty | 846.4 KiB | pg_ai_query_15-0.1.1-1PIGSTY.el10.aarch64.rpm |
postgresql-15-ai-query |
0.1.1 |
d13.x86_64 | pigsty | 841.4 KiB | postgresql-15-ai-query_0.1.1-1PIGSTY~trixie_amd64.deb |
postgresql-15-ai-query |
0.1.1 |
d13.aarch64 | pigsty | 758.6 KiB | postgresql-15-ai-query_0.1.1-1PIGSTY~trixie_arm64.deb |
postgresql-15-ai-query |
0.1.1 |
u24.x86_64 | pigsty | 795.2 KiB | postgresql-15-ai-query_0.1.1-1PIGSTY~noble_amd64.deb |
postgresql-15-ai-query |
0.1.1 |
u24.aarch64 | pigsty | 771.6 KiB | postgresql-15-ai-query_0.1.1-1PIGSTY~noble_arm64.deb |
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_ai_query_14 |
0.1.1 |
el9.x86_64 | pigsty | 967.8 KiB | pg_ai_query_14-0.1.1-1PIGSTY.el9.x86_64.rpm |
pg_ai_query_14 |
0.1.1 |
el9.aarch64 | pigsty | 881.0 KiB | pg_ai_query_14-0.1.1-1PIGSTY.el9.aarch64.rpm |
pg_ai_query_14 |
0.1.1 |
el10.x86_64 | pigsty | 899.3 KiB | pg_ai_query_14-0.1.1-1PIGSTY.el10.x86_64.rpm |
pg_ai_query_14 |
0.1.1 |
el10.aarch64 | pigsty | 846.4 KiB | pg_ai_query_14-0.1.1-1PIGSTY.el10.aarch64.rpm |
postgresql-14-ai-query |
0.1.1 |
d13.x86_64 | pigsty | 841.6 KiB | postgresql-14-ai-query_0.1.1-1PIGSTY~trixie_amd64.deb |
postgresql-14-ai-query |
0.1.1 |
d13.aarch64 | pigsty | 760.7 KiB | postgresql-14-ai-query_0.1.1-1PIGSTY~trixie_arm64.deb |
postgresql-14-ai-query |
0.1.1 |
u24.x86_64 | pigsty | 795.2 KiB | postgresql-14-ai-query_0.1.1-1PIGSTY~noble_amd64.deb |
postgresql-14-ai-query |
0.1.1 |
u24.aarch64 | pigsty | 771.7 KiB | postgresql-14-ai-query_0.1.1-1PIGSTY~noble_arm64.deb |
Source
pig build pkg pg_ai_query; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_ai_query; # install via package name, for the active PG version
pig install pg_ai_query -v 18; # install for PG 18
pig install pg_ai_query -v 17; # install for PG 17
pig install pg_ai_query -v 16; # install for PG 16
pig install pg_ai_query -v 15; # install for PG 15
pig install pg_ai_query -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_ai_query;Usage
pg_ai_query generates SQL queries from natural language descriptions using LLM providers (OpenAI, Anthropic, Google Gemini). It introspects your database schema and translates plain-English questions into SQL.
Configuration
Create ~/.pg_ai.config:
[general]
log_level = "INFO"
enable_logging = false
[query]
enforce_limit = true
default_limit = 1000
[response]
show_explanation = true
show_warnings = true
[openai]
api_key = "your-openai-api-key"
default_model = "gpt-4o"
[anthropic]
api_key = "your-anthropic-api-key"
default_model = "claude-3-5-sonnet-20241022"
[gemini]
api_key = "your-google-api-key"
default_model = "gemini-2.5-flash"Query Generation
SELECT generate_query('show all customers');
SELECT generate_query('monthly sales trend for the last year by category');
SELECT generate_query('customers who have not placed orders in the last 6 months');Schema Discovery
SELECT get_database_tables();
SELECT get_table_details('orders');Query Explanation
SELECT explain_query('SELECT * FROM users WHERE created_at > NOW() - INTERVAL ''7 days''');Pass API credentials directly:
SELECT explain_query('SELECT * FROM products WHERE price > 100', 'your-api-key', 'anthropic');Supported Models
- OpenAI: gpt-4o, gpt-4o-mini
- Anthropic: claude-3-5-sonnet-20241022, claude-3-haiku-20240307
- Google Gemini: gemini-2.5-pro, gemini-2.5-flash
Last updated on