-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AQL: function to get collection by name? #1138
Comments
You are right, there is currently no such function in AQL. |
Thinking a bit about this: |
Is this feature implemented till now?
but i get: |
No, this is not implemented yet, because of the above concerns. Note that you could use a bind parameter for the collection name, but that also requires the collection name to be known already when executing the query. So it won't be dynamic in the sense that the collection name is calculated from intermediate query results. |
If all access to a single collection is required but the collection name should not be hard-coded in the AQL query, then a bind parameter can be used as follows:
or
(with bind parameter What also works in 2.8 is injecting the collection name into AQL functions like this:
What will not work is something like this:
The above will simply iterate over an array with two strings, but not over an array with 2 collections. Having a function such as The reason is that we need to create query execution plans directly after parsing the query, and at point it will be unclear which collections will take part in the query. The execution plan parts may even be shipped around in a cluster to start the query, and making this all dynamic and happen at run-time while the query is running will require a completely new implementation. |
Any update on this since 2015? It would be very helpful to keep all of the logic in AQL rather than having to bring it out to js to get and bind a collection reference. |
Sorry, no update on this since 2014/2015. The execution of an AQL query works as follows:
Steps 2 to 5 need to know which collections are involved. For example, the optimizing step selects the indexes to use, which is obviously collection-dependent. The distribution step also needs some knowledge about where shards are actually located. |
Via email from mstrofbass:
Would something like this be achievable by using a placeholder that the parser recognizes and replaces with the collection names during the parsing phase?
Late-bound collections / dynamic collection lookups won't be implemented as @jsteemann explained.
If you look for a way to write queries without hardcoding collection names, use bind parameters. They are resolved at query compile time, so not dynamic, but you can use the same query and execute it with different bind parameters to run it against different collections:
https://docs.arangodb.com/3.3/AQL/Fundamentals/BindParameters.html
|
There is
COLLECTIONS()
to retrieve all collections, but I'm not aware of a function to get a single collection by name / id.I would like the following to work:
The text was updated successfully, but these errors were encountered: