Translate questions about e-mails into SQL queries and run them
Configured with Agent, Chat Trigger, Convert To File, Execute Workflow Trigger, and additional nodes. Review the connections and setup before adapting this template.
Node categories in this workflow
- Transform
- Files / media
- Trigger
- Routing
- Data store
- AI & models
Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.
Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.
How it works
The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.
| Node | Category | Type | Operation |
|---|---|---|---|
| Add table name to output | Transform | Edit Fields | See node parameters |
| Convert data to binary | Transform | Convert To File | toJson |
| Save file locally | Files / media | Read Write File | write |
| Extract data from file | Transform | Extract From File | fromJson |
| Chat Trigger | Trigger | Chat Trigger | See node parameters |
| When clicking "Test workflow" | Trigger | Manual Trigger | See node parameters |
| Combine schema data and chat input | Transform | Edit Fields | See node parameters |
| Load the schema from the local file | Files / media | Read Write File | See node parameters |
| Extract SQL query | Transform | Edit Fields | See node parameters |
| Check if query exists | Routing | If | See node parameters |
| Format query results | Transform | Edit Fields | See node parameters |
| Combine query result and chat answer | Transform | Merge | See node parameters |
| List all columns in a table | Data store | Postgres | executeQuery |
| List all tables in a database | Data store | Postgres | executeQuery |
| Ollama Chat Model | AI & models | LM Chat Ollama | See node parameters |
| Postgres | Data store | Postgres | executeQuery |
| Add trailing semicolon | Transform | Edit Fields | See node parameters |
| Check for trailing semicolon | Routing | If | See node parameters |
| WorkflowTrigger | Trigger | Execute Workflow Trigger | See node parameters |
| If ran manually | Routing | If | See node parameters |
| If file exists or already retried generating it | Routing | If | See node parameters |
| AI Agent | AI & models | Agent | See node parameters |
| Format empty output | Transform | Edit Fields | See node parameters |
Setup
- Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
- Connect your own credentials through n8n’s credential store. Replace
REPLACE_WITH_*values with your resource identifiers. - Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
- Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.
Requirements
An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.
Credential types declared in the source
None declared. HTTP requests and Code nodes may still need configuration.
Workflow notes
This can run manually
This can run manually
This section:
- loads a list of all tables from the database
- extracts the database schema for each table and adds the table name
- converts the schema into a binary JSON format
- saves the schema file locally
This is triggered by chat or as a sub-workflow
This is triggered by chat or as a sub-workflow
Natural language requests can be asked, and a SQL query as well as its results will be returned.
Quite the prompt 😅
Quite the prompt 😅
Some refined prompt engineering work here.
It may or may not been done aided by Kagi's Assistant and Claude 3.7 Sonnet 👀
Translate questions about e-mails into SQL queries and run them
Translate questions about e-mails into SQL queries and run them
Purpose and structure
This folder contains the Translate questions about e-mails into SQL queries and run them workflow. Its executable nodes use agent, chatTrigger, convertToFile, executeWorkflowTrigger, extractFromFile, if, lmChatOllama, manualTrigger, merge, postgres, readWriteFile, set. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.
Setup
Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.
Entry points
Chat Trigger, When clicking "Test workflow", WorkflowTrigger
Verification
Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.
Attribution
https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Postgres/1245_Postgres_Extractfromfile_Automation_Triggered.json MIT; preserve source notices.