# Array to one item for Postgres INSERT

**URL:** <https://community.n8n.io/t/array-to-one-item-for-postgres-insert/4662>\
**Category:** Questions\
**Created:** [March 8, 2021, 8:03am UTC](https://community.n8n.io/t/array-to-one-item-for-postgres-insert/4662 "2021-03-08T08:03:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![a1ekseev](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@a1ekseev](https://community.n8n.io/u/a1ekseev)\
**Post date:** [March 8, 2021, 8:03am UTC](https://community.n8n.io/t/array-to-one-item-for-postgres-insert/4662/1 "2021-03-08T08:03:29Z")

</div>

HI!  
When I fetch data from Postgres I get in response:

```
[
  {
    "id": "67c64fb6-c8a3-4d0b-bfcc-07731ea9878f"
  },
  {
    "id": "01794f93-06f0-45e2-9f48-4cbe68c6bf37"
  }
]

```

How do I put this together in one line? For the query:

```
INSERT INTO table (id, name) VALUES (...) , (...)
ON CONFLICT 
DO NOTTING;
```

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [March 8, 2021, 8:54am UTC](https://community.n8n.io/t/array-to-one-item-for-postgres-insert/4662/2 "2021-03-08T08:54:33Z")

</div>

You can do that in a Function-Node. Not sure where you get the name from, so did now simply hardcode it to a static value.

Here the code:

```javascript
return [
  {
    json: {
      query: 'INSERT INTO table (id, name) VALUES ' + items.map(item => `("${item.json.id}", "the name")`).join(', ') + ' ON CONFLICT DO NOTHING;'
    }
  }
];

```

And here an example workflow:

---

<div class="post-metadata">

**Author:** ![a1ekseev](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@a1ekseev](https://community.n8n.io/u/a1ekseev)\
**Post date:** [March 8, 2021, 2:04pm UTC](https://community.n8n.io/t/array-to-one-item-for-postgres-insert/4662/3 "2021-03-08T14:04:45Z")

</div>

When I added this to my workflow I got:

```
ReferenceError: items is not defined
```

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [March 8, 2021, 2:56pm UTC](https://community.n8n.io/t/array-to-one-item-for-postgres-insert/4662/4 "2021-03-08T14:56:58Z")

</div>

That is not possible. Please copy the workflow JSON I posted above and past it into yours. It has to work.
