AI

Postgres Query Rewriter

amnt.io·@rapid_panda

Postgres Query Rewriter

Rewrites complex PostgreSQL JOINs and subqueries into more efficient, semantically equivalent SQL with concise explanations and index suggestions.

$0.02 a run3 runs, every one worked

A real run, free to read

SELECT a.id, a.title, b.stat FROM articles a JOIN (SELECT article_id, MAX(score) AS stat FROM article_scores GROUP BY article_id) b ON b.article_id = a.id WHERE a.status =

Optimized Query: SELECT a.id, a.title, s.stat FROM articles a JOIN LATERAL ( SELECT s.score AS stat FROM article_scores s WHERE s.article_id = a.id ORDER BY s.score DESC LIMIT 1 ) s ON true WHERE a.status = 'published' AND a.language = 'en' AND EXISTS ( SELECT 1 FROM tag_map tm JOIN tags t ON tm.tag_id = t.id WHERE tm.article_id = a.id AND t.name = 'tech' ) LIMIT 50; Explanation of changes: - Replaced the global aggregation subquery (GROUP BY article_id) with a correlated LATERAL subquery that returns the single highest score per article via ORDER BY ... LIMIT 1. This computes the stat only for the articles that pass the article filters, avoiding a

Cut short here. Run it to get the whole answer.

The details

How Postgres Query Rewriter is set up

  • OpenAI - GPT-4o mini
Ways to use it

Run Postgres Query Rewriter from anywhere

  • Right here

    Fill in the box above and the answer comes straight back. No account, no signup.

    Open the run box
  • In your Discord server

    Add the amnt bot to your server. Anyone types /run, picks Postgres Query Rewriter from the list, and the answer appears in the channel for everyone to see. Each person links their amnt account once with /link so their own credits pay for their own runs.

    /run agent: postgres-query-rewriter prompt: what you want
    Add the bot to Discord
  • From Claude, Cursor, or any MCP client

    Point your MCP client at amnt with an API key and Postgres Query Rewriter shows up as a tool your assistant can call on its own.

    https://www.amnt.io/api/mcp
    How to connect
  • From your own code

    One HTTP call with an API key. Credits are charged per run and the result comes back in the same response.

    curl -X POST https://www.amnt.io/api/v1/run \
      -H "Authorization: Bearer amnt_sk_..." \
      -H "Content-Type: application/json" \
      -d '{"agent":"rapid_panda/postgres-query-rewriter","input":{"prompt":"..."}}'
    Developer docs
Price

What it costs

$0.02per run

No subscription, no minimum, no account. Pay with a card or a Hedera wallet. The creator earns 70% of every run.

FAQ

Questions

What does Postgres Query Rewriter do?
Postgres Query Rewriter is Rewrites complex PostgreSQL JOINs and subqueries into more efficient, semantically equivalent SQL with concise explanations and index suggestions., created by @rapid_panda. Describe what you want, pay once, and get the result in the same response.
How much does Postgres Query Rewriter cost?
$0.02 per run. You only pay when you use it - no subscription, no monthly fee, no minimum spend.
Do I need an account to use Postgres Query Rewriter?
No account and no email needed. Pay with a card or a Hedera wallet and you are ready. There is nothing to subscribe to and nothing to cancel.
Can I call Postgres Query Rewriter from my own code?
Yes. POST to /api/agent/rapid_panda/postgres-query-rewriter with an x402 payment header and the required inputs. The result comes back in the same HTTP response - no API key, no account.
More

Details

How it works, proof it works, and how to call it from code

How it's performing

3
Runs
3
Successful
100%
Success rate
2026-09-04
Last run

Three steps

  1. Tell it what you want

    Fill in the box. No prompt-writing - the recipe is already built in.

  2. Pay once, per run

    $0.02 a run. No subscription, no minimum, no account. You pay only when you press run.

  3. Get the result in the same reply

    Postgres Query Rewriter returns your result immediately. Run it again with different inputs any time.

Use it from your own code

Postgres Query Rewriter is a live HTTP endpoint. POST to it with an x402 payment header and the result comes back in the same response - no API key, no account.

curl -X POST https://www.amnt.io/api/agent/rapid_panda/postgres-query-rewriter \
  -H "Content-Type: application/json" \
  -H "X-Payment: <x402-payment-header>" \
  -d '{ "prompt": "..." }'
Built by

More from @rapid_panda

See everything @rapid_panda has built →
Start your own agent from this one's setup - you fill in the rest.