Skip to content

SQL Runner Test Workflow

A simple HTTP-to-SQL execution service that accepts SQL queries via webhook and executes them against a PostgreSQL database, returning the results as JSON.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

This workflow appears to be a testing or development utility that provides a direct HTTP interface for executing SQL queries against a database. It could be used for debugging, data exploration, or as a backend service for applications that need to run dynamic SQL queries.

How It Works

  1. Receive Request: The workflow listens for HTTP POST requests at the /sifa-sql endpoint
  2. Extract SQL: It extracts the SQL query from the request body, handling both string format and nested object format
  3. Execute Query: The SQL query is executed against a PostgreSQL database
  4. Return Results: Query results are returned as JSON to the caller

Workflow Diagram

graph TD
    A[Webhook<br/>POST /sifa-sql] --> B[Execute SQL<br/>PostgreSQL Query]
    B --> C[Return Results<br/>JSON Response]

Trigger

Webhook (HTTP POST) - Endpoint: /sifa-sql - Method: POST - Authentication: None - Expected Payload: JSON with sql field containing the query to execute

Nodes Used

Node Type Node Name Purpose
Webhook Webhook Receives HTTP POST requests and extracts SQL query from body
PostgreSQL Execute SQL Executes the SQL query against the configured database

External Services & Credentials Required

PostgreSQL Database

  • Credential Name: "Postgres account"
  • Required Fields:
    • Host/Server
    • Port (default: 5432)
    • Database name
    • Username
    • Password
    • SSL settings (if required)

Environment Variables

No environment variables are explicitly used in this workflow. All configuration is handled through n8n credentials.

Data Flow

Input

HTTP POST request to /sifa-sql with JSON body:

1
2
3
{
  "sql": "SELECT * FROM users WHERE id = 1"
}

Or nested format:

1
2
3
4
5
{
  "sql": {
    "sql": "SELECT * FROM users WHERE id = 1"
  }
}

Output

JSON response containing query results:

1
2
3
4
5
6
7
[
  {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com"
  }
]

Error Handling

This workflow has minimal error handling: - Database connection errors will be returned as HTTP errors - SQL syntax errors will be returned as HTTP errors - No input validation is performed on the SQL query - No authentication or authorization checks are implemented

Known Limitations

  • Security Risk: No authentication means anyone with the webhook URL can execute arbitrary SQL queries
  • No Input Validation: Malicious SQL queries could potentially damage the database
  • No Query Limits: Long-running queries could consume excessive resources
  • No Logging: No audit trail of executed queries
  • Single Database: Only supports one PostgreSQL connection

No related workflows identified from the provided context.

Setup Instructions

  1. Import Workflow

    • Copy the workflow JSON
    • In n8n, go to Workflows → Import from JSON
    • Paste the JSON and save
  2. Configure PostgreSQL Credentials

    • Go to Credentials → Add Credential
    • Select "Postgres"
    • Enter your database connection details
    • Name it "Postgres account" (or update the workflow to match your credential name)
  3. Activate Workflow

    • Open the workflow
    • Click the "Active" toggle to enable it
  4. Test the Webhook

    • Copy the webhook URL from the Webhook node
    • Send a POST request with SQL query:
      1
      2
      3
      curl -X POST [webhook-url] \
        -H "Content-Type: application/json" \
        -d '{"sql": "SELECT NOW()"}'
      
  5. Security Considerations

    • Consider adding authentication to the webhook
    • Implement input validation and query sanitization
    • Restrict database user permissions to minimum required
    • Monitor and log query execution for security auditing