Insert error on postgres database

Hi,

I have this error during insert data in my postgres database :

error: syntax error at or near ")"
    at Parser.parseErrorMessage (/usr/local/lib/node_modules/n8n/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/usr/local/lib/node_modules/n8n/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/usr/local/lib/node_modules/n8n/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

my postgres node :

    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO main.coinmarket  VALUES ({{$node[\"Function\"].json[\"id\"]}}, '{{$node[\"Function\"].json[\"name\"]}}','{{$node[\"Function\"].json[\"symbol\"]}}',{{$node[\"Function\"].json[\"cmc_rank\"]}},{{$node[\"Function\"].json[\"price\"]}},{{$node[\"Function\"].json[\"circulating_supply\"]}},{{$node[\"Function\"].json[\"volume_24h\"]}},{{$node[\"Function\"].json[\"percent_change_1h\"]}},{{$node[\"Function\"].json[\"percent_change_24h\"]}},{{$node[\"Function\"].json[\"percent_change_7d\"]}},{{$node[\"Function\"].json[\"market_cap\"]}},'{{$node[\"Function\"].json[\"last_updated\"]}}'::timestamp, {{$node[\"Function\"].json[\"max_supply\"]}}) ON CONFLICT (id) DO NOTHING",
        "additionalFields": {}
      },
      "name": "Postgres",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        990,
        280
      ],
      "credentials": {
        "postgres": "DB"
      }
    },

You have to share the whole workflow. A single node cannot be paste in the workflow editor.

{
  "name": "CoinMarket",
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO main.coinmarket  VALUES ({{$node[\"Function\"].json[\"id\"]}}, '{{$node[\"Function\"].json[\"name\"]}}','{{$node[\"Function\"].json[\"symbol\"]}}',{{$node[\"Function\"].json[\"cmc_rank\"]}},{{$node[\"Function\"].json[\"price\"]}},{{$node[\"Function\"].json[\"circulating_supply\"]}},{{$node[\"Function\"].json[\"volume_24h\"]}},{{$node[\"Function\"].json[\"percent_change_1h\"]}},{{$node[\"Function\"].json[\"percent_change_24h\"]}},{{$node[\"Function\"].json[\"percent_change_7d\"]}},{{$node[\"Function\"].json[\"market_cap\"]}},'{{$node[\"Function\"].json[\"last_updated\"]}}'::timestamp, {{$node[\"Function\"].json[\"max_supply\"]}}) ON CONFLICT (id) DO NOTHING",
        "additionalFields": {}
      },
      "name": "Postgres",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        990,
        280
      ],
      "credentials": {
        "postgres": "Warren"
      }
    },
    {
      "parameters": {
        "functionCode": "const cryptos = []\nitems.map(function(item) {\n    item.json.data.map(function (crypto){\n        cryptos.push({\n          json: { \n            id: crypto.id, \n            name: crypto.name,\n            symbol: crypto.symbol,\n            cmc_rank: crypto.cmc_rank,\n            last_updated: crypto.quote.USD.last_updated,\n            price: crypto.quote.USD.price,\n            circulating_supply: crypto.circulating_supply,\n            max_supply: crypto.max_supply,\n            volume_24h: crypto.quote.USD.volume_24h,\n            percent_change_1h: crypto.quote.USD.percent_change_1h,\n            percent_change_24h: crypto.quote.USD.percent_change_24h,\n            percent_change_7d: crypto.quote.USD.percent_change_7d,\n            market_cap: crypto.quote.USD.market_cap\n            }\n          })\n    })\n }) ;\n \n \nreturn cryptos"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        750,
        270
      ]
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?limit=50",
        "responseFormat": "=json",
        "jsonParameters": "true",
        "options": {}
      },
      "name": "Api",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        550,
        290
      ],
      "credentials": {
        "httpHeaderAuth": "CoinMarket Prod"
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        320,
        170
      ]
    }
  ],
  "connections": {
    "Api": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Postgres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Api",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "1"
}

I found the solution, i had an empty value in my last insert parameter.

1 Like

Thanks for sharing the solution with the community.