# Repeat action like with recursive

**URL:** <https://community.easymorph.com/t/repeat-action-like-with-recursive/2919>\
**Category:** Support\
**Created:** [July 26, 2021, 2:09pm UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919 "2021-07-26T14:09:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvo](https://community.easymorph.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cvo](https://community.easymorph.com/u/cvo)\
**Post date:** [July 26, 2021, 2:09pm UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919/1 "2021-07-26T14:09:04Z")

</div>

Greetings,

I try to replace recursive query done in SQLite with repeat actions.  
I'm missing something but I don't succeed to get the same result.

the test dataset is  
SLAVE\_ID  
MASTER\_ID  
SLAVE\_CAT : an ID can be SLAVE ONLY, BOTH or MASTER ONLY  
MASTER\_CAT : an ID can be BOTH or MASTER ONLY  
the PATH is the concatenation of the IDs  
the DEPTH\_TREE is the DEPTH of the PATH so it should be the number of iteration - 1

question :

- I don't succeed to specify simply conditional root points, in my case the ID with the attribute 'SLAVE ONLY' in SLAVE\_CAT
- I don't succeed to fully explore the hierarchy to get the upper PATH\_ID,  
if I use sc.PATH\_ID || '\>' || c.SLAVE\_ID I never get the last path,  
if I use sc.PATH\_ID || '\>' || c.MASTER\_ID then I can't get the root path with only the SLAVE\_ID

The repeat action seems very powerful as it give the possibility to make recursive outer join (never seen that anywhere else) but it is not that intuitive at first look.

In the repeat loop, is there is a system variable that sends back the current iteration number ? This way we could handle exception in the first iteration.

the structure of the query is

WITH RECURSIVE temp\_table AS  
(  
SELECT DISTINCT  
SLAVE\_ID AS INIT\_ID,  
SLAVE\_ID,  
MASTER\_ID,  
SLAVE\_CAT AS INIT\_CAT,  
SLAVE\_CAT,  
MASTER\_CAT,  
0 AS DEPTH\_TREE,  
CAST ( SLAVE\_ID as text) AS PATH\_ID  
FROM recurtest  
WHERE SLAVE\_CAT = 'SLAVE ONLY'  
UNION  
SELECT DISTINCT  
sc.INIT\_ID AS INIT\_ID,  
c.SLAVE\_ID AS SLAVE\_ID,  
c.MASTER\_ID AS MASTER\_ID,  
sc.INIT\_CAT AS INIT\_CAT,  
c.SLAVE\_CAT AS SLAVE\_CAT,  
c.MASTER\_CAT AS MASTER\_CAT,  
sc.DEPTH\_TREE + 1 AS DEPTH\_TREE,  
sc.PATH\_ID || '\>' || c.SLAVE\_ID AS PATH\_ID  
FROM  
temp\_table AS sc  
JOIN  
recurtest AS c  
ON  
sc.MASTER\_ID = c.SLAVE\_ID  
)  
SELECT DISTINCT  
INIT\_ID,  
SLAVE\_ID,  
MASTER\_ID,  
INIT\_CAT,  
SLAVE\_CAT,  
MASTER\_CAT,  
DEPTH\_TREE,  
PATH\_ID  
FROM  
temp\_table;

Regards

[extract closure.zip](https://community.easymorph.com/uploads/short-url/xt3YHyrzfbdtAKiM4gipjV5qei4.zip) (3.9 KB)

---

<div class="post-metadata">

**Author:** ![dgudkov](https://community.easymorph.com/user_avatar/community.easymorph.com/dgudkov/32/5_2.png) [@dgudkov](https://community.easymorph.com/u/dgudkov)\
**Post date:** [July 26, 2021, 9:56pm UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919/2 "2021-07-26T21:56:13Z")

</div>

Hi Christophe,

I'm not familiar with recursive SQL, can't comment on that.

A convenient way to debug a recursive "Repeat" iteration is to populate the "Input" action of the iterated module. In the 1st iteration, it's the input dataset of the "Repeat" action itself.

To debug 2nd and further iterations, send the result table of the iterated module into the "Input" action of the same module. Go to the last action in the result table, right-click it and choose "Send to module". In this case, you can walk each recursive iteration one by one while clearly seeing what's in the input and what's in the output of the iterated module.

---

<div class="post-metadata">

**Author:** ![cvo](https://community.easymorph.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cvo](https://community.easymorph.com/u/cvo)\
**Post date:** [July 27, 2021, 10:19am UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919/3 "2021-07-27T10:19:36Z")

</div>

the debugging mode step by step is impressive.  
I understood my issue,  
hard to catch the subtilities of 'Repeat' vs 'With recursive' :  
in EM, when we select 'Append' option, the append is done after all the iterations are done. It's a kind of Traversal Search.  
In a recursive query, the 'appended' table is reinjected on each iteration, it's a Breadth-first search.  
So I have to make the append in the loop and select 'Return last not empty result' if I want the Repeat to behave like With recursive

Regards

---

<div class="post-metadata">

**Author:** ![dgudkov](https://community.easymorph.com/user_avatar/community.easymorph.com/dgudkov/32/5_2.png) [@dgudkov](https://community.easymorph.com/u/dgudkov)\
**Post date:** [July 27, 2021, 10:48am UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919/4 "2021-07-27T10:48:21Z")

</div>

Do you mind posting the updated example?

---

<div class="post-metadata">

**Author:** ![cvo](https://community.easymorph.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cvo](https://community.easymorph.com/u/cvo)\
**Post date:** [July 27, 2021, 11:04am UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919/5 "2021-07-27T11:04:29Z")

</div>

I understood my mistake, I didn't corrected it yet...  
I have a few other tests to proceed : I'll post the interesting ones.

---

<div class="post-metadata">

**Author:** ![cvo](https://community.easymorph.com/letter_avatar_proxy/v4/letter/c/a88e57/32.png) [@cvo](https://community.easymorph.com/u/cvo)\
**Post date:** [August 10, 2021, 3:04pm UTC](https://community.easymorph.com/t/repeat-action-like-with-recursive/2919/6 "2021-08-10T15:04:23Z")

</div>

[EM repeat with table.zip](https://community.easymorph.com/uploads/short-url/fRQ9CuOCNKWh9wN5YwPMXs1LjBL.zip) (6.1 KB)  
Hi,

Here is an example of 'with recursive' SQL behavior

Regards
