pg-aiguide is a powerful MCP server and Claude plugin designed to enhance PostgreSQL coding. It provides comprehensive documentation and tools to help AI coding tools generate optimized PostgreSQL code efficiently.
claude install timescale/pg-aiguidehttps://mcp.tigerdata.com/docs
["1. Identify the specific PostgreSQL task you need to accomplish (e.g., data retrieval, aggregation, or complex joins).","2. Determine the performance metrics that are most important for your query (e.g., read speed, write efficiency, or memory usage).","3. List potential error conditions that your query might encounter (e.g., missing data, invalid inputs, or permission issues).","4. Use pg-aiguide to generate the optimized PostgreSQL code by providing the task, performance metrics, and error conditions.","5. Test the generated code in your PostgreSQL environment and refine it as needed. Use tools like pgAdmin or DBeaver for testing and debugging."]
Generate optimized PostgreSQL queries that follow best practices.
Automate the generation of complex database schemas tailored to specific applications.
Provide comprehensive documentation on PostgreSQL features and best practices.
Assist developers in debugging and refining PostgreSQL code for better performance.
claude install timescale/pg-aiguidegit clone https://github.com/timescale/pg-aiguideCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Generate a PostgreSQL query to [TASK] using pg-aiguide. The query should optimize for [PERFORMANCE_METRIC] and include error handling for [ERROR_CONDITIONS]. Provide the query in a format compatible with [DATABASE_TOOL].
To optimize the performance of a customer data retrieval query, pg-aiguide generated the following PostgreSQL code:
```sql
CREATE OR REPLACE FUNCTION get_customer_data(customer_id INT)
RETURNS TABLE (
customer_id INT,
name VARCHAR,
email VARCHAR,
last_purchase DATE,
total_spent NUMERIC
) AS $$
BEGIN
RETURN QUERY
SELECT
c.customer_id,
c.name,
c.email,
o.purchase_date AS last_purchase,
SUM(o.amount) AS total_spent
FROM
customers c
LEFT JOIN
orders o ON c.customer_id = o.customer_id
WHERE
c.customer_id = get_customer_data.customer_id
GROUP BY
c.customer_id, c.name, c.email, o.purchase_date
ORDER BY
o.purchase_date DESC
LIMIT 1;
END;
$$ LANGUAGE plpgsql;
-- Error handling for cases where customer_id doesn't exist
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM customers WHERE customer_id = 12345) THEN
RAISE NOTICE 'Customer with ID 12345 does not exist.';
END IF;
END $$;
```
This query optimizes for read performance by using appropriate indexing and limiting the result set. It includes error handling for non-existent customer IDs and is compatible with tools like pgAdmin or DBeaver.AI assistant built for thoughtful, nuanced conversation
Orchestrate workloads with multi-cloud support, job scheduling, and integrated service discovery features.
Serverless MySQL database platform
Design, document, and generate code for APIs with interactive tools for developers.
CI/CD automation with build configuration as code
Enhance performance monitoring and root cause analysis with real-time distributed tracing.
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan