AutomationFlowsData & Sheets › List Pending Text-to-SQL Queries from Postgres

List Pending Text-to-SQL Queries from Postgres

Original n8n title: Text-to-sql: List Pending Queries

Text-to-SQL: List Pending Queries. Uses postgres. Webhook trigger; 5 nodes.

Webhook trigger★★★★☆ complexity5 nodesPostgres
Data & Sheets Trigger: Webhook Nodes: 5 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "Text-to-SQL: List Pending Queries",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "pending-queries",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook3",
      "name": "Webhook - List Pending",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT\n  job_id,\n  question,\n  schema_info,\n  environment,\n  language,\n  user_id,\n  created_at,\n  EXTRACT(EPOCH FROM (NOW() - created_at)) as age_seconds\nFROM sql_queue\nWHERE status = 'pending'\nORDER BY created_at ASC\nLIMIT 50;",
        "options": {}
      },
      "id": "postgres4",
      "name": "Get Pending from DB",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.4,
      "position": [
        450,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT\n  environment,\n  status,\n  COUNT(*) as count\nFROM sql_queue\nWHERE created_at > NOW() - INTERVAL '24 hours'\nGROUP BY environment, status\nORDER BY environment, status;",
        "options": {}
      },
      "id": "postgres5",
      "name": "Get Queue Stats",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.4,
      "position": [
        450,
        450
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Merge pending queries and stats\nconst pendingQueries = $input.item(0).json;\nconst stats = $input.item(1).json;\n\n// Calculate totals\nconst totalPending = pendingQueries.length;\nconst oldestAgeSeconds = totalPending > 0 ? pendingQueries[0].age_seconds : 0;\n\n// Group stats by environment\nconst statsByEnv = {};\nstats.forEach(s => {\n  if (!statsByEnv[s.environment]) {\n    statsByEnv[s.environment] = {};\n  }\n  statsByEnv[s.environment][s.status] = s.count;\n});\n\nreturn {\n  total_pending: totalPending,\n  oldest_age_seconds: oldestAgeSeconds,\n  oldest_age_minutes: Math.round(oldestAgeSeconds / 60 * 10) / 10,\n  requests: pendingQueries,\n  stats_24h: statsByEnv,\n  recommendation: totalPending > 20 \n    ? 'High queue load - consider batch processing' \n    : totalPending > 0 \n    ? 'Ready for processing' \n    : 'No pending requests'\n};"
      },
      "id": "code2",
      "name": "Format Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "id": "respond3",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "Webhook - List Pending": {
      "main": [
        [
          {
            "node": "Get Pending from DB",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Queue Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Pending from DB": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Queue Stats": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "id": "text-to-sql-pending",
  "tags": [
    {
      "createdAt": "2025-01-23T00:00:00.000Z",
      "updatedAt": "2025-01-23T00:00:00.000Z",
      "id": "1",
      "name": "text-to-sql"
    }
  ]
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Text-to-SQL: List Pending Queries. Uses postgres. Webhook trigger; 5 nodes.

Source: https://github.com/GalSened/text-to-sql-teams-bot/blob/2850aece4e7c0fd2ef2ca9211c0830ffffc51414/n8n-workflows/list_pending.json — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Data & Sheets

Scraping. Uses httpRequest, postgres, @apify/n8n-nodes-apify, respondToWebhook. Webhook trigger; 61 nodes.

HTTP Request, Postgres, @Apify/N8N Nodes Apify
Data & Sheets

Workflow B — AI Listing Engine. Uses httpRequest, postgres, errorTrigger. Webhook trigger; 47 nodes.

HTTP Request, Postgres, Error Trigger
Data & Sheets

How it works

Postgres, Email Send
Data & Sheets

This workflow automates data maturity evaluation to measure how well an organization uses data to create value by capturing assessment data through forms or APIs, processing and scoring responses usin

Email Send, Postgres
Data & Sheets

Orders. Uses postgres. Webhook trigger; 26 nodes.

Postgres