Hey n8n community,
I’m encountering an issue with the PostgreSQL node when trying to insert or update data into a jsonb[] column. Here’s the situation:
What I’m Trying to Achieve:
- I have a column named
assetsin my PostgreSQL table, which is of typejsonb[]. - I want to insert or update this column with an array of JSON objects directly from my workflow without manually writing SQL commands.
Current Behavior:
- When I attempt to set the
assetscolumn value directly as an array of objects (using expressions like{{ $json.assets }}), I get the following error:
Error;
Invalid input for 'assets' [item 0]
'assets' expects a array but we got '::jsonb[]'
- I’ve tried to explicitly cast the value to
jsonb[]within the node’s interface by using{{ $json.assets }}::jsonb[], but this approach results in the node interpreting::jsonb[]as part of the data rather than a SQL cast.
Expected Behavior:
- The node should recognize the incoming data as an array of JSON objects and automatically handle the conversion to PostgreSQL’s
jsonb[]type without needing manual SQL casting in the node interface.
Steps to Reproduce:
- Set up a workflow where
assetsis an array of objects. - Use a PostgreSQL node for Insert or Update operation.
- Map the
assetsfield from your data to theassetscolumn in the table, using expressions if necessary. - Attempt to execute the workflow.
Additional Information:
- n8n version: 1.72.1
- Database: postgresdb
- n8n EXECUTIONS_PROCESS setting: own, main
- Running n8n via: Docker
- Operating system: Linux
- PostgreSQL version: 16.1
Example of data structure for assets:
[
{
"assetKey": "exampleKey",
"campaignId": "exampleId",
"punchCount": 0,
"assignDate": "2024-12-17T19:29:45.976Z",
"redeemed": false
}
]
Has anyone else encountered this issue? Any suggestions for handling this without resorting to custom SQL queries directly in the node? Or is there a known workaround?
Thanks for any help or insights!
