PostgreSQL AI SQL Generator

Generate queries for PostgreSQL with AI

Database Setup
Configure your database connection and schema

Step 1 Select your database

Step 2 Run this query to get your database schema

SELECT 
    t.table_name,
    c.column_name,
    c.data_type,
    CASE WHEN pk.column_name IS NOT NULL THEN 'PRI' ELSE '' END as column_key
  FROM information_schema.tables t
  JOIN information_schema.columns c ON t.table_name = c.table_name
  LEFT JOIN (
    SELECT tc.table_name, kcu.column_name
    FROM information_schema.table_constraints tc
    JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name
    WHERE tc.constraint_type = 'PRIMARY KEY'
  ) pk ON t.table_name = pk.table_name AND c.column_name = pk.column_name
  WHERE t.table_schema = 'public'
  ORDER BY t.table_name, c.ordinal_position;

Step 3 Paste the results from the above query

Step 4 Describe what you want to query

Example Query
See how the AI generates SQL from natural language
-- Find all customers who made purchases over $1000 last month
SELECT c.name, SUM(o.amount) as total_spent
FROM customers c
JOIN orders o ON c.id = o.customer_id
WHERE o.date >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY c.id
HAVING total_spent > 1000;