Automation library · Content

Query Google Sheets/CSV data with PostgreSQL

Started by an event in a connected app, and works across Google Sheets and Postgres. It hands the judgement calls to Gemini. 20 steps, 1 branch: a working afternoon to understand properly.

MediumCalls a model: Gemini

20 stepsMedium: a working afternoon
1Branch: places the flow splits
0Loops or waits
2Services it connects to

The flow

Starts it 3Model 4Logic 6Service 7

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

  1. 1Google Drive TriggerGoogle Drive triggerStarts it
  2. 2execute_query_toolTool WorkflowModel
  3. 3Google Gemini Chat ModelLm Chat Google GeminiModel
  4. 4get_postgres_schemaTool WorkflowModel
  5. 5Execute Workflow TriggerExecute Workflow triggerStarts it
  6. 6When chat message receivedManual Chat triggerStarts it
  7. 7change_thisSetLogic
  8. 8AI Agent With SQL Query PromptAgentModel
  9. 9sql query executorPostgresService
  10. 10schema finderPostgresService
  11. 11table exists?PostgresService
  12. 12response outputSetLogic
  13. 13schema to stringCodeLogic
  14. 14fetch sheet dataGoogle SheetsService
  15. 15is not in databaseIfLogic
  16. 16create table queryCodeLogic
  17. 17remove tablePostgresService
  18. 18create tablePostgresService
  19. 19create insertion queryCodeLogic
  20. 20perform insertionPostgresService

How it's built

Starts on
An event in a connected app
Steps
20, with 1 branch
Size
Medium: a working afternoon
Connects to
Google Sheets, Postgres
Model
Gemini

Questions

What does it need to run?

An n8n account, plus your own Google Sheets and Postgres 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?

Plan an afternoon. 20 steps is enough that you should read each one before running it.

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 20 steps before you point it at anything that matters.