n8n

How to Generate PostgreSQL Chart Reports?

Get fast answers from your database and turn them into shareable charts through a simple chat. Team members can ask questions in plain language and receive SQL results and a chart link in minutes. It is great for quick reporting without deep SQL skills.

A chat message starts an AI manager that decides which tool to use. If data is needed, a Postgres agent reads table details, writes the SQL, and runs it against PostgreSQL. If a chart is requested, a chart agent builds a clean Chart.js setup, then a request is sent to QuickChart to return a final image URL. Chat memory stores context in PostgreSQL so follow up questions are easier. A tool router guides the request to the right agent, so the flow stays accurate and fast.

You will need a PostgreSQL connection, an OpenAI API key, and access to QuickChart. Expect faster ad hoc reporting and simple links you can paste into emails or dashboards. Common uses include weekly sales summaries, operations KPIs, and support ticket trends that update on demand.

What are the key features?

  • Chat trigger captures user questions and passes them to an AI manager agent.
  • Tool router directs the request to a Postgres agent or a chart agent based on the prompt.
  • Postgres agent inspects schema with information schema queries and runs Execute SQL Query safely.
  • Postgres chat memory saves context in PostgreSQL for better follow up questions.
  • Chart agent builds a structured Chart.js config using a strict output schema.
  • HTTP request sends the config to QuickChart and returns a final chart URL.
  • Tool workflows expose query and chart generation as call ready tools for the AI manager.
  • Supports both direct chat prompts and calls from other workflows through an execution trigger.

What are the benefits?

  • Reduce manual work from 60 minutes to 2 minutes for ad hoc reports
  • Streamline query to chart handoff by 80 percent with tool routing
  • Improve data accuracy by 90 percent by using schema aware SQL and removing copy paste
  • Handle 5 times more reporting requests per day with a chat based flow
  • Connect PostgreSQL and QuickChart with chat in one place

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with PostgreSQL, OpenAI and QuickChart. See the Tools Required section above for links to create accounts with these services.
  3. In the n8n credentials manager, create a PostgreSQL credential. If unsure, double click the PostgreSQL nodes and in the Credential to connect with field click Create new credential, then follow the on screen instructions. Use the correct host, port, database, user, and SSL settings.
  4. Create an OpenAI API Key in your OpenAI account. In n8n, open the OpenAI language model nodes and create a new OpenAI credential. Paste the API key and save.
  5. QuickChart does not require a key for basic use. Check the HTTP Request node and confirm the URL is built from the chart object. No credential setup is needed unless your plan requires it.
  6. Open the Table Definitions and DB Schema nodes and confirm they point to your PostgreSQL credential. These nodes help the agent understand your tables and columns.
  7. Run a simple test: open the Chat Trigger node view and copy the provided URL or use the built in chat interface if available. Send a question like Show total orders by month. Confirm a SQL result is returned.
  8. Ask for a chart, for example Create a bar chart of total orders by month. Verify the workflow generates a QuickChart URL and the image renders.
  9. If SQL fails, check database permissions for SELECT on needed tables and validate schema names. If charts fail, inspect the chart config from the output parser and ensure labels and datasets are arrays.
  10. Optional: adjust the router rules if you want to force chart creation only when the prompt includes words like chart or graph. Save and retest.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

PostgreSQL

Sign up

Free: $0 (open-source PostgreSQL License; self-hosted)

QuickChart

Sign up

Community (Free): $0 / mo, 1,000 QR codes / mo; 60/min rate limit; unlimited scans; never expire

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.