PostgreSQL with an AI Agent: Example Requests and Routines
· DoubleX
Quick answer
An AI agent connected to PostgreSQL in read-only mode can answer questions about your tables in plain English, run data checks, summarize results, and produce recurring reports. With DoubleX IA OS, it can also send results to Google Sheets or Slack, without changing any data in the database.
Technical and data teams spend a lot of time on small, repeated database questions: how many orders came in yesterday, which accounts have no owner, why a count does not match a dashboard. An AI agent with read-only access to PostgreSQL can take on this kind of work while your data stays untouched.
What can an AI agent do with a read-only PostgreSQL database?#
An AI agent is an assistant that uses a model, instructions, and connected tools to do work for you. With the PostgreSQL connector, it can query the tables of your database directly, in read-only mode, and turn what it finds into answers, summaries, and reports.
In practice, that covers four kinds of work:
- Questions in plain language: you describe what you want to know and the agent queries the tables.
- Checks: looking for duplicates, empty fields, or records that look out of place.
- Summaries: counts, totals, and comparisons between periods.
- Recurring reports: the same analysis on a schedule, delivered where your team already works.
Because the connection is read-only, the agent cannot insert, update, or delete rows. If you need a field changed, the agent can tell you which records to fix, and a person makes the change.
If you have not connected the database yet, start with How to Connect PostgreSQL to an AI Agent, Step by Step.
Which requests work best for querying and summarizing tables?#
The best requests name the table or the business concept, the time period, and the format you want back. The agent reads your schema, writes the query, and explains what it found.
Here are examples you can copy and adapt:
- "List the tables in this database and describe what each one seems to store."
- "How many new customers were created in the last 7 days, grouped by day?"
- "Find orders with no matching customer record and show the first 20."
- "Compare the number of support tickets this month with last month, by category."
- "Check the users table for duplicate email addresses and tell me how many there are."
| Task | How the agent helps | Where it works |
|---|---|---|
| Exploring an unfamiliar schema | Lists tables and columns and explains them | PostgreSQL |
| Daily or weekly counts | Runs the query and summarizes the result | PostgreSQL |
| Data quality checks | Looks for duplicates, nulls, and orphan records | PostgreSQL |
| Sharing results | Writes rows to a spreadsheet | Google Sheets |
| Alerting the team | Posts a short summary to a channel | Slack |
How do you generate a weekly report from the database on a schedule?#
You ask the agent to do the analysis once, check that the result is right, and then turn the request into a routine. A routine is a trigger that makes the agent work on its own, for example every Monday at 8am, using the permissions of the person who created it.
Here is the flow in DoubleX IA OS:
- Create your account and, if you want a starting point, take the diagnostic, a 5 to 10 minute conversation about your routine that turns into a team of agents.
- Open Connectors and connect PostgreSQL. It runs in read-only mode by default.
- In Agents, create or open the agent that will do the reporting and choose which systems it can use and which actions it can run.
- Ask for the report in Tasks and review the result. Adjust the request until the numbers and the format are what you want.
- Schedule it with a trigger, such as every Monday at 8am, and describe where the result should go.
Triggers can also run once on a set date, every hour, or when a webhook arrives. See Triggers for the details.
A good weekly request looks like this:
- "Every Monday at 8am, count new signups, paid orders, and open support tickets from the past 7 days, compare them with the previous week, and write a short summary with the three biggest changes."
How do you combine the data with Google Sheets or send it to Slack?#
You connect Google Sheets or Slack as additional connectors and ask the agent to use the database result in the next step. The agent queries PostgreSQL in read-only mode, then writes the output to the other system.
Some combinations that teams use:
- Database to Google Sheets: the agent queries a table and appends rows to a spreadsheet, or creates a new sheet for the week.
- Google Sheets to database check: the agent reads a list of IDs from a sheet and checks which ones exist in PostgreSQL.
- Database to Slack: the agent posts a short summary of the weekly numbers to a channel.
Example requests:
- "Query paid orders from yesterday and add one row per order to the 'Daily orders' sheet."
- "Read the customer IDs in column A of the 'Churn review' sheet and tell me which ones have no activity in the database in the last 60 days."
- "Send a three-line summary of this week's signups to the #growth channel on Slack."
Since Sheets and Slack can receive data, actions like writing rows or sending messages can be limited in the agent's permissions. The agent asks for confirmation before sending or changing something in those systems.
For another Postgres option, see How to Connect Neon to an AI Agent and Query Postgres.
How does the agent show its steps, and what does it not change?#
Every request becomes a task with a full history: the request, each tool the agent used, and the result. You can see who asked, what ran, and when. The PostgreSQL connector is read-only, so the agent does not modify your tables.
This gives you three layers of control:
- Read-only database access: no inserts, updates, or deletes.
- Per-agent permissions: you choose which systems each agent uses and which actions it can run in each one.
- Confirmation and history: before sending, deleting, or changing something in other systems, the agent asks for confirmation and shows what it did.
Your company content is also not used to train models, and each company has its own separate database inside the platform. You can read more in the Introduction.
What good practices avoid heavy queries and sensitive data?#
Keep requests specific, limit the scope of what the agent can see, and review results before sharing them. Most problems come from broad questions on large tables or from sending raw data to places where many people can read it.
- Limit the period and the rows. Ask for "the last 7 days" or "the first 50 rows" instead of a full table scan.
- Ask for aggregates when you can. Counts and totals are lighter and safer to share than full lists of customers.
- Use a database user with limited access. Create a user that can read only the tables the agent needs.
- Avoid sensitive columns. Leave out personal data, such as documents or contact details, unless the task needs them.
- Schedule heavy reports off-peak. Run big analyses early in the morning rather than during business hours.
- Test before scheduling. Run the request manually once and read the history before turning it into a routine.
Frequently asked questions#
Can the agent change or delete data in PostgreSQL?#
No. The PostgreSQL connector works in read-only mode, so the agent can query tables but not insert, update, or delete rows.
Do I need to write SQL to use this?#
No. You describe what you want in your own words and the agent builds the query. If you know SQL, you can read the steps in the task history and check what ran.
Can the agent run reports without me asking each time?#
Yes. You can schedule a routine, for example every Monday at 8am, and it runs with the permissions of the person who created it.
Can the agent send results to my team?#
Yes, through connectors such as Slack or Google Sheets. The agent asks for confirmation before sending or changing something in those systems.
Does my database content train AI models?#
No. Your company content is not used to train models, and requests go only to AI providers that do not use what they receive for training.
Related guides
- How to Connect PostgreSQL to an AI Agent, Step by StepLearn how to connect PostgreSQL to an AI agent in read-only mode: prepare a safe database user, add the connector, set permissions, and test it.
- How to Connect Neon to an AI Agent and Query PostgresLearn how to connect Neon Postgres to an AI agent in DoubleX IA OS: pick the connection scope, limit actions, start read-only, and test your first query.
- How to Connect Gmail to an AI Agent, Step by StepLearn how to connect Gmail to an AI agent: add the connector, choose personal, team or company access, and set what the agent can read, draft or send.