Automation library · Content

Query PostgreSQL from Slack with Google Sheets and Gemini

Started by an event in a connected app, and works across Google Sheets, Postgres and Slack. It hands the judgement calls to Gemini. 21 steps, 3 branches: large, and worth reading before you trust it with anything live.

LargeCalls a model: Gemini

21 stepsLarge: read it before trusting it with anything live
3Branches: places the flow splits
0Loops or waits
3Services it connects to

The flow

Starts it 1Model 3Logic 13Service 4

The steps in the order they run, from what starts it.

  1. 1Slack TriggerSlack triggerStarts it
  2. 2Extract Slack MessageSetLogic
  3. 3Load Table DefinitionsGoogle SheetsService
  4. 4Prepare Table ListCodeLogic
  5. 5Load Database SchemaPostgresService
  6. 6Build AI SchemaCodeLogic
  7. 7Generate SQLGoogle GeminiModel
  8. 8Parse LLM ResultCodeLogic
  9. 9Handle Failure ResponseSetLogic
  10. 10Validate LLM OutputCodeLogic
  11. 11Send Slack ReplySlackService
  12. 12SQL Valid?IfLogic
  13. 13Execute SQL QueryPostgresService
  14. 14Determine Failure CauseIfLogic
  15. 15Format Query ResultCodeLogic
  16. 16Output Creation(Gemini)Google GeminiModel
  17. 17Regenerate SQLGoogle GeminiModel
  18. 18Prepare Slack ResponseCodeLogic
  19. 19Parse AI Response (Retry)CodeLogic
  20. 20Validate SQL (Retry)CodeLogic
  21. 21SQL Valid? (Retry)IfLogic

How it's built

Starts on
An event in a connected app
Steps
21, with 3 branches
Size
Large: read it before trusting it with anything live
Connects to
Google Sheets, Postgres, Slack
Model
Gemini

Questions

What does it need to run?

An n8n account, plus your own Google Sheets, Postgres and Slack accounts, and a key for Gemini. You connect your own accounts after importing it; none are included.

What starts it?

It starts on an event in a connected app.

Does it use AI?

Yes. It calls Gemini. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Take your time. At 21 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

Before you run it

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 21 steps before you point it at anything that matters.