using neo4j enterprise server v 5.26.1 with browser v 5.26.2
I read the following fragment from the neo4j manual v 2025.02 (current):
Please, note the colored statement at the end of the page.
In other word, I understand that I cannot write to more than 1 graph at a time when using federated databases
.
Given this, can someone explain me why the following query returns an error?
USE federatedNotions.customer
match (n)-[r]-(m)
USE federatedNotions.notions
merge (n)-[r]-(m)
return n,r,m
Note that in this query I'm matching from
just one graph and writing to
just another graph, as required by the manual.
The way I understand it, is that you can't access difference composite database in the same transaction. In your case, you are accessing two different compositions dbs in the same transaction. I think you can wrap the second query in a call subquery. In this case, I don't think a merge makes sense when trying to merge nodes/relationships from a different composite database. It would make more sense to create new nodes and relationships in the second composite database using properties from the first composite database.
hy Gary, apart of the merge, it return an error as soon as I try to change the DB:
use federatednotions.sorodipy
match (n)-[r]-(m)
call {
with n,r,m
use federatednotions.notions
return n
}
return n
Neo.ClientError.Statement.SyntaxError
Multiple graphs in the same query not allowed here. This feature is only available on composite databases.
Attempted to access graph federatednotions.notions (line 5, column 5 (offset: 74))
" use federatednotions.notions"
^
Can you provide a valid example?
The error seems to imply ‘federatednotations’ is not a composite database. Did you create a composite database using ‘create composite database federatednotations’? You can view your databases with “show databases”.
In your new version, the outer scope uses federatednotations.sorodipy, while the inner query uses a different database. The screenshot about states that nested subqueries can’t use different databases. The nested queries must use the same database as its outer query.
Try this structure. The outer query does not specify a database, so each inner query can use their own.
call {
use federatednotions.sorodipy
match (n)-[r]-(m)
return, n, r, m
}
call {
use federatednotions.notions
with n, r, m
//do something
return n as new_n
}
return new_n
your sample looks fine: here is my db delcaration (I deleted other lines):
name type aliases access address role writer requestedStatus currentStatus statusMessage default home constituents
"federatednotions" "composite" [] "read-only" "localhost:7687" null false "online" "online" "" false false ["federatednotions.sarobidymercerie", "federatednotions.carts", "federatednotions.conversations", "federatednotions.gdpr", "federatednotions.geolocations", "federatednotions.notions", "federatednotions.sarobidy"]
This is a list of the graph included into the composite DB `sarobidymercerie
but, when I try your solution, it return me the usual error:
and here we have a new kind of error:
BTW, your sample failed too!
There is another question for you: https://community.neo4j.com/t/apoc-crypto-encrypt-and-apoc-crypto-decrypt/72913
. give it a look, please!
I was able to try this in version 5.26.1. I got the same error when I executed the query in the neo4j database. It worked when I switched to my composite database and then ran the same query. Did you switch over to your composite db first? The screenshot does not show the database name in the prompt.
Execution in composite db 'comp':
Executing in other database 'neo4j':
I cannot understand: yes, you must be switched to a composite DB before running the query. I've done it. but now the result is just more criptic: whic kind of variable can I pass to a subquesry (call), and why importing node values is currently not supported
???
Apart of this, it is very dangerous if a USE statement doesn't run:
I'd like to put a USE federatednotions
on top of everything and then be sure that the data are moved between the database I specify.
But if the USE
statement just fails and the query is executed on another DB, it should be a disaster!
It looks like the node 'n' from the 'gdpr' graph cannot be imported into the subquery that uses the 'notations' graph. This makes sense to me, as the node entity is from an entirely different graph.
What you can do is return the elements of the node that you want to use in the subquery using the 'notations' graph. This way you can create/merge nodes with these properties in the 'notations' graph.
Something like this:
call {
use comp.alias_db1
match (n:X)
return labels(n) as labels, properties(n) as props
}
call {
use comp.alias_db2
with labels, props
create(m:$(labels))
set m = props
return m
}
return m