How to query Graph in recursive way? #2998
Replies: 7 comments
-
No one? |
Beta Was this translation helpful? Give feedback.
-
Recursive queries are a requirement for my use case, is there no way to do them ? |
Beta Was this translation helpful? Give feedback.
-
There are only Record Links, which in my opinion are quite enough to work with. And they work, even if queried multiple times. Based on the CREATEs from the documentation you are able to do:
I dont see any use case for real recursive queries without having cursor support. Or you may provide one? |
Beta Was this translation helpful? Give feedback.
-
Leta say I have departments. And every department can have a sub-department, related in a MANAGED_BY relation. And it goes all the way from the lowest department and up to the CEO office in an hierarchical order.
I now want to draw the path from the lowest department to the CEO via MANAGED_BY. yet I don't know how many level would be. In one branch of the tree it's three, yet in another branch it's 20... How can you draw this path only by keeping surreal db busy, and not the server's CPU?
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: dkr8toha ***@***.***>
Sent: Tuesday, May 14, 2024 12:36:16 AM
To: surrealdb/surrealdb ***@***.***>
Cc: Bokitza ***@***.***>; Comment ***@***.***>
Subject: Re: [surrealdb/surrealdb] How to query Graph in recursive way? (Discussion #2998)
There are only Record Links<https://surrealdb.com/docs/surrealdb/surrealql/datamodel/records>, which in my opinion are quite enough to work with. And they work, even if queried multiple times. Based on the CREATEs from the documentation you are able to do:
SELECT * FROM person WHERE name = "Tobie" FETCH friends
,friends.friends
,friends.friends.friends
,friends.friends.friends.friends
,friends.friends.friends.friends.friends
I dont see any use case for real recursive queries without having cursor support.
Or you may provide one?
—
Reply to this email directly, view it on GitHub<#2998 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AN3UDNWKW52RMILD6LV7F73ZCEW5BAVCNFSM6AAAAAA7RYXVHCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TIMRWGIZTI>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Currently this is the only possible way i think:
The following query will work:
but must be extended (currently supports a depth of 5)... will result in:
This works but well is a bit ugly :-) I agree that there should be some query operator to recursively collect and expand the item like:
something like this:
Ye i know, this is not the nested set you want to have but i personally hate the nesting ...... |
Beta Was this translation helpful? Give feedback.
-
should be
or
to define a maximum depth ..... |
Beta Was this translation helpful? Give feedback.
-
I have a similar use case, one table that can link back on itself. A really nice way IMO to write the query would be to introduce an
|
Beta Was this translation helpful? Give feedback.
-
Given that I have a person table. And I insert thousands of record:
Then I make the relation like:
Since the length of knows is arbitrary. I could not know how many levels there shall be.
But the result I would like to have is to get the response including all the levels. The format may like this:
Can anyone share how to deal with this user case?
Beta Was this translation helpful? Give feedback.
All reactions