logo
icon

PostgreSQL with AI Query (dev version)

PostgreSQL with pg_ai_query extension for natural language SQL generation powered by OpenAI and Anthropic AI models

template cover
Deployed7 times
Publishercanyugs
Created2025-11-27
Services
service icon

PostgreSQL with AI Query Extension

A powerful PostgreSQL database with built-in AI capabilities for generating SQL queries from natural language.

Features

  • Natural Language to SQL: Convert plain English to SQL queries
  • Multiple AI Providers: Support for OpenAI (GPT-4o, GPT-4) and Anthropic (Claude)
  • Automatic Schema Discovery: AI understands your database structure
  • Query Performance Analysis: Get AI-powered optimization suggestions
  • Built on PostgreSQL 17: Latest stable PostgreSQL version

Quick Start

1. Configure AI Provider

Edit the config file ~/.pg_ai.config to set at least one API key:

2. Connect to Database

Use the connection string from the service instructions.

3. Start Using AI Queries

-- Generate queries from natural language
SELECT generate_query('show all customers who registered in the last 30 days');

-- Explore your database structure
SELECT get_database_tables();
SELECT get_table_details('users');

-- Analyze query performance
SELECT explain_query('SELECT * FROM users WHERE created_at > NOW() - INTERVAL ''7 days''');

Example Use Cases

-- Business analytics
SELECT generate_query('monthly sales trend for the last year by category');

-- Customer insights
SELECT generate_query('top 10 customers by total purchase amount');

-- Data quality
SELECT generate_query('find duplicate email addresses in the users table');

-- Complex joins
SELECT generate_query('users who have placed orders but never left a review');

Documentation

Notes

  • The extension requires an active internet connection to call AI APIs
  • Each query generation consumes API credits
  • Keep your API keys secure and monitor usage