# :auto transaction doesn't run as described in the manual

**URL:** <https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847>\
**Category:** Cypher\
**Tags:** performance, cypher, import\
**Created:** [May 5, 2022, 5:32pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847 "2022-05-05T17:32:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 5, 2022, 5:32pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/1 "2022-05-05T17:32:29Z")

</div>

I'm running neo4j server community 4.4.5 with browser 4.4.3 on Ubuntu 20.04 machine.

This is from the online manual:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/9/b/9b99ed50227aefd1099621d14e324051339a8f3b.png)

This is the error:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/c/c/ccd8122a4e57ac2e08f0c22199135595e1a1078b.png)

And this is the query

```auto
:auto LOAD CSV WITH HEADERS FROM 'file:///transactions.csv' AS row FIELDTERMINATOR ';'

CALL {
WITH row
WITH row
    WHERE row.id IS NOT NULL

OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)})

OPTIONAL MATCH (bankAccount:BankAccount {id: toInteger(row.bank_account_id)})

MERGE (transaction:Transaction { id : toInteger(row.id) })
		SET transaction = row,
			transaction.uuid = apoc.create.uuid(),
            transaction.id = toInteger(row.id),
            transaction.consumer_id = NULL // remove the attribute no more used

    WITH transaction, row, bankAccount, organisation

CALL {
    WITH transaction, row, bankAccount
    WITH transaction, row, bankAccount
        WHERE bankAccount IS NOT NULL

    MERGE (transaction)-[h:HAS]->(bankAccount)
}

CALL {
    WITH transaction, row, bankAccount
    WITH transaction, row, bankAccount
        WHERE bankAccount IS NULL
    
    MERGE (error:Error)
    MERGE (transaction)-[h:HAS_NO_BANK_ACCOUNT]->(error)
}

CALL {
    WITH transaction, row, organisation
    WITH transaction, row, organisation
        WHERE organisation IS NOT NULL

    MERGE (transaction)-[h:BELONGS_TO]->(organisation)
}

CALL {
    WITH transaction, row, organisation
    WITH transaction, row, organisation
        WHERE organisation IS NULL
    
    MERGE (error:Error)
    MERGE (transaction)-[h:HAS_NO_ORGANISATION]->(error)
}

} IN TRANSACTIONS;

```

I tried to make some changes but with no luck!

Any suggestion?

---

<div class="post-metadata">

**Author:** ![Rcolinp](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rcolinp/32/22908_2.png) [@Rcolinp](https://community.neo4j.com/u/Rcolinp)\
**Post date:** [May 5, 2022, 6:39pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/2 "2022-05-05T18:39:03Z")

</div>

Hey there!

From a brief peek at your cypher code snippet, it appears you are hitting that error due to a syntax error on row 5? I was able to reproduce your query above (different data) using v4.4.5 (I am in v4.4.5 browser though).

I believe you are seeing an error because you are following the `CALL { with row with row` with a `WHERE` clause.

i.e. -\> You have:

```cypher
:auto LOAD CSV WITH HEADERS FROM 'file:///transactions.csv' AS row 
CALL { 
WITH row
WITH row 
      WHERE row.id IS NOT NULL
...

```

What you may want is to tuck that where clause in your `OPTIONAL MATCH`. Something like this:

```cypher
:auto LOAD CSV WITH HEADERS FROM 'file:///transactions.csv' AS row 
CALL { WITH row WITH row 
OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)}) WHERE ...

```

Reading through regarding auto transactions, I don't think you can use a WHERE clause there... 🤔

I hope this somewhat helps and there isn't much else to it. Post back here if you are seeing same thing. I'd be curious what is throwing that error if it isn't how you are stating `WHERE row.id IS NOT NULL`.

Cheers,  
Rob

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 5, 2022, 8:32pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/3 "2022-05-05T20:32:23Z")

</div>

You may recall you had a query a few weeks back that had nested CALL subqueries and returned the same error. In that case, I was not able to get rid of the error and ended up refactoring the query not to have nested CALLs. I did the same in this case using the apoc 'when' method to replace the use of the inner CALL subqueries used to mimic if/else functionality.

The query executes, but I don't have test data to validate it is actually working. The 'RETURN 1' statements were necessary to make it execute, since I got errors about 'can't terminate without a RETURN statement'.

```auto
:auto LOAD CSV WITH HEADERS FROM 'file:///Book1.csv' AS row FIELDTERMINATOR ';'
WITH row
WHERE row.id IS NOT NULL

CALL {
    WITH row

    OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)})

    OPTIONAL MATCH (bankAccount:BankAccount {id: toInteger(row.bank_account_id)})

    MERGE (transaction:Transaction { id : toInteger(row.id) })
		SET transaction = row,
			transaction.uuid = apoc.create.uuid(),
            transaction.id = toInteger(row.id),
            transaction.consumer_id = NULL // remove the attribute no more used

    WITH transaction, row, bankAccount, organisation

    CALL apoc.when(bankAccount IS NOT NULL, 
    'MERGE ($tran)-[h:HAS]->($bankAcct)', 
    'MERGE (error:Error) MERGE ($tran)-[h:HAS_NO_BANK_ACCOUNT]->(error)',
    {tran: transaction, bankAcct: bankAccount}) yield value

    with transaction, organisation

    CALL apoc.when(organisation IS NOT NULL, 
    'MERGE ($tran)-[h:BELONGS_TO]->($org)',
    'MERGE (error:Error) MERGE ($tran)-[h:HAS_NO_ORGANISATION]->(error)',
    {tran: transaction, org: organisation}) yield value

    RETURN 1

} IN TRANSACTIONS
RETURN 1

```

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 5, 2022, 8:55pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/4 "2022-05-05T20:55:35Z")

</div>

I tried another approach that allowed me to eliminate the extra return statements. I used some 'list filtering' to simulate an 'if' capability. Each of the lists 'bankAcctNotNull', 'bankAcctIsNull', 'organisationNotNull', and 'organisationIsNull' will either be empty or contain a single value of '1', depending on the 'is null / is not null' conditions. As such, the 'foreach' loops will either execute one time or zero times.

Again, the query runs but I have not tested it.

```auto
:auto LOAD CSV WITH HEADERS FROM 'file:///Book1.csv' AS row FIELDTERMINATOR ';'
WITH row
WHERE row.id IS NOT NULL

CALL {
    WITH row

    OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)})

    OPTIONAL MATCH (bankAccount:BankAccount {id: toInteger(row.bank_account_id)})

    MERGE (transaction:Transaction { id : toInteger(row.id) })
		SET transaction = row,
			transaction.uuid = apoc.create.uuid(),
            transaction.id = toInteger(row.id),
            transaction.consumer_id = NULL // remove the attribute no more used

    WITH transaction, row, bankAccount, organisation, 
    [i in [1] where bankAccount IS NOT NULL] as bankAcctNotNull,
    [i in [1] where bankAccount IS NULL] as bankAcctIsNull,
    [i in [1] where organisation IS NOT NULL] as organisationNotNull,
    [i in [1] where organisation IS NULL] as organisationIsNull

    foreach(i in bankAcctNotNull | 
        MERGE (transaction)-[h:HAS]->(bankAccount)
    )

    foreach(i in bankAcctIsNull | 
        MERGE (error:Error) 
        MERGE (transaction)-[h:HAS_NO_BANK_ACCOUNT]->(error)
    )

    foreach(i in organisationNotNull | 
        MERGE (transaction)-[h:BELONGS_TO]->(organisation)
    )

    foreach(i in organisationIsNull | 
        MERGE (error:Error) 
        MERGE (transaction)-[h:HAS_NO_ORGANISATION]->(error)
    )

} IN TRANSACTIONS

```

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 5, 2022, 9:37pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/5 "2022-05-05T21:37:59Z")

</div>

@glilienfield The latter looks really interesting! I'll try it tomorrow!

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 8:07am UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/6 "2022-05-06T08:07:07Z")

</div>

The second WITH is used to filter the row.id, and it is trick because in a call the first WITH cannot be filtered.  
It has ran until now, I don't think it is the problem, because if I remove it the problem remains.  
I'm just moving to the latest 4.4.6, then let you know ....

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 12:04pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/7 "2022-05-06T12:04:10Z")

</div>

@glilienfield@Rcolinp I used the first solution from @glilienfield : it is much more readable of the second, despite the return statement.  
You can remove the second `return 1` statement: it runs without.

So, the problem key are the nested calls: if you have a running query with `CALL {} IN TRANSACTIONS` and add a nested `CALL {}` doing nothing, the entire query fails with an error.

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/8/0/80100b3af417e74f2adef3fa6e605262ac54f4d1.png)

While the same query without the inner call, succeeds (without any return!):

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/6/c/6c974bcf33290d959390f783f044ae2a54ed784a.png)

This latest to demonstrate the usage of the double `WITH ROW` inside the CALL. With only one it doesn't run with the `WHERE` clause:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/b/7/b764bbe8c58d36a3d1a96a02efa90a9cd41aa115.png)

Now a question is still open: What is the meaning of using `:auto` combined with using `WITH TRANSACTIONS OF 100 ROWS`? Who has the precedence? `:auto` or `100`?

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 2:18pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/8 "2022-05-06T14:18:46Z")

</div>

> [@glilienfield](#):
>
> ```auto
> WITH transaction, row, bankAccount, organisation
> 
> ```

Unfortunately, it looks nice but run badly 🤬

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/2/5/25bb54d7999c7e7ec1a16e6b2eea10675e21f2f3.png)

Why not simply this way? (We need `apoc.do.when` because we are writing ....)

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/e/1/e1a983c94c0846be060263d65d5d1c703765527d.png)

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 6, 2022, 2:38pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/9 "2022-05-06T14:38:20Z")

</div>

That is what I originally had, but I thought it would not recognize the variables 'transaction', 'organization', and bankAccount' when the apoc routine executed the cypher. I did not try it to verify. Did you try it?

The error looks like you can't use the passed parameters in the match pattern.

---

<div class="post-metadata">

**Author:** ![bennu\_neo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bennu_neo/32/27616_2.png) [@bennu\_neo](https://community.neo4j.com/u/bennu_neo)\
**Post date:** [May 6, 2022, 2:42pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/10 "2022-05-06T14:42:53Z")

</div>

Hi @glilienfield ,

With $tran he will look for the variable within the outer scope. With tran alone should work.

Bennu

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 6, 2022, 3:03pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/11 "2022-05-06T15:03:26Z")

</div>

I had passed the variables from the outer scope as parameters to the apoc method, then referenced the parameters in the cypher. It looks like it does not like using parameters in replacement of match binder variables.

I just did an experiment. the apoc method did not recognize variables defined outside the method. This make sense to me, as the cypher will not have knowledge of these variables when it is executed on the server.

I tried this as a work around. I bound the passed parameters to variables in a 'with' clause, which can them be used in the match pattern.

```auto
:auto LOAD CSV WITH HEADERS FROM 'file:///Book1.csv' AS row FIELDTERMINATOR ';'
WITH row
WHERE row.id IS NOT NULL

CALL {
    WITH row

    OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)})

    OPTIONAL MATCH (bankAccount:BankAccount {id: toInteger(row.bank_account_id)})

    MERGE (transaction:Transaction { id : toInteger(row.id) })
		SET transaction = row,
			transaction.uuid = apoc.create.uuid(),
            transaction.id = toInteger(row.id),
            transaction.consumer_id = NULL // remove the attribute no more used

    WITH transaction, row, bankAccount, organisation

    CALL apoc.do.when(bankAccount IS NOT NULL, 
    'WITH $tran as tran, $bankAcct as bankAcct MERGE (tran)-[h:HAS]->(bankAcct)', 
    'WITH $tran as tran MERGE (error:Error) MERGE (tran)-[h:HAS_NO_BANK_ACCOUNT]->(error)',
    {tran: transaction, bankAcct: bankAccount}) yield value

    with transaction, organisation

    CALL apoc.do.when(organisation IS NOT NULL, 
    'WITH $tran as tran, $org as org MERGE (tran)-[h:BELONGS_TO]->(org)',
    'WITH $tran as tran MERGE (error:Error) MERGE (tran)-[h:HAS_NO_ORGANISATION]->(error)',
    {tran: transaction, org: organisation}) yield value

    RETURN 1

} IN TRANSACTIONS

RETURN 1

```

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 3:12pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/12 "2022-05-06T15:12:09Z")

</div>

I'll give you another point to think about: the `:auto` keyword doesn't like to the `cypher-shell`!

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 3:30pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/13 "2022-05-06T15:30:04Z")

</div>

Well, I gave it this version and it partially run:

But I have 895 nodes, and if I check I have 895 `:HAS_NO_BANK_ACCOUNT` but 0 `:HAS_NO_ORGANIZATION` AND 0 `:BELONGS_TO`. Still cannot explain

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/4/d/4d1434aa15444016ad5eae955736a89e27830457.png)

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 3:49pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/14 "2022-05-06T15:49:00Z")

</div>

@glilienfield @Rcolinp @bennu_neo Yes, I tried a lot of times, the first APOC.DO.WHEN runs fine, but the second APOC.DO.WHEN is never executed!

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 6, 2022, 4:13pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/15 "2022-05-06T16:13:54Z")

</div>

Can you please try reversing the order? Does the 'organisation' one now run and the 'bankAccount' when doesn't?

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 4:16pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/16 "2022-05-06T16:16:00Z")

</div>

Already done: it stops after the first one!

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 6, 2022, 4:42pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/17 "2022-05-06T16:42:22Z")

</div>

I think it may be caused by not returning a value from the 'when' cypher statements. I added returns. I also rearranged some things, but that should have no effect.

Try this:

```auto
:auto 
LOAD CSV WITH HEADERS FROM 'file:///Book1.csv' AS row FIELDTERMINATOR ';'
WITH row
WHERE row.id IS NOT NULL

CALL {
    WITH row

    MERGE (transaction:Transaction { id : toInteger(row.id) })
		SET transaction = row,
			transaction.uuid = apoc.create.uuid(),
            transaction.id = toInteger(row.id),
            transaction.consumer_id = NULL // remove the attribute no more used

    WITH transaction, row

    OPTIONAL MATCH (bankAccount:BankAccount {id: toInteger(row.bank_account_id)})

    CALL apoc.do.when(bankAccount IS NOT NULL, 
    'WITH $tran as tran, $bankAcct as bankAcct MERGE (tran)-[h:HAS]->(bankAcct) return 1', 
    'WITH $tran as tran MERGE (error:Error) MERGE (tran)-[h:HAS_NO_BANK_ACCOUNT]->(error) return 1',
    {tran: transaction, bankAcct: bankAccount}) yield value

    with transaction, row

    OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)})

    CALL apoc.do.when(organisation IS NOT NULL, 
    'WITH $tran as tran, $org as org MERGE (tran)-[h:BELONGS_TO]->(org) return 1',
    'WITH $tran as tran MERGE (error:Error) MERGE (tran)-[h:HAS_NO_ORGANISATION]->(error) return 1',
    {tran: transaction, org: organisation}) yield value

    RETURN 1

} IN TRANSACTIONS

RETURN 1

```

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 4:44pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/18 "2022-05-06T16:44:46Z")

</div>

I have already tried this too: moving the optional matches below doesn't change anything.

BTW: You other solutions run as a charme, but I would like to figure this out and understand this unusual behavior

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 6, 2022, 4:45pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/19 "2022-05-06T16:45:52Z")

</div>

with the return statements added to the 'when' cypher? I tested it locally with similar code and it executed both 'when' statements.

---

<div class="post-metadata">

**Author:** ![paolodipietro58](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/paolodipietro58/32/21045_2.png) [@paolodipietro58](https://community.neo4j.com/u/paolodipietro58)\
**Post date:** [May 6, 2022, 4:50pm UTC](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847/20 "2022-05-06T16:50:06Z")

</div>

Yes, It don't execute the second `when`. I changed the names to the relationships, so I can check if it creates one branch or the other, and I have no relationships from the second WHEN.

```auto
WITH row
    WHERE row.transactionid IS NOT NULL

MERGE (transaction:Transaction { transactionid : row.transactionid })
        SET transaction = row,
            transaction.uuid = apoc.create.uuid(),
            transaction.consumer_id = NULL // remove the attribute no more used

    with transaction, row
    
    OPTIONAL MATCH (organisation:Organisation {id: toInteger(row.organisation_id)})

    CALL apoc.do.when(organisation IS NOT NULL, 
    'WITH $tran as tran, $org as org MERGE (tran)-[h:TRANSACTION_BELONGS_TO_ORGANISATION]->(org)',
    'WITH $tran as tran MERGE (error:Error) MERGE (tran)-[h:TRANSACTION_HAS_NO_ORGANISATION]->(error)',
    {tran: transaction, org: organisation}) yield value AS X

    WITH transaction, row

    OPTIONAL MATCH (bankAccount:BankAccount {id: toInteger(row.bank_account_id)})

    CALL apoc.do.when(bankAccount IS NOT NULL, 
    'WITH $tran as tran, $bankAcct as bankAcct MERGE (tran)-[h:TRANSACTION_HAS_BANK_ACCOUNT]->(bankAcct)', 
    'WITH $tran as tran MERGE (error:Error) MERGE (tran)-[h:TRANSACTION_HAS_NO_BANK_ACCOUNT]->(error)',
    {tran: transaction, bankAcct: bankAccount}) yield value AS Y

return 1

} IN TRANSACTIONS OF 5000 ROWS

return 1;

```

[Next page](https://community.neo4j.com/t/auto-transaction-doesnt-run-as-described-in-the-manual/55847.md?page=2)
