Error in a federated database: cannot run schema operations : how to solve it?

Running neo4j enterprise 5.26.2.

I got the following error while try to set KEYS and CONSTRAINTS on a federated database:

Moreover, it looks like I cannot change database while I've choosen one in the list box on top left.

How can I decide throught a query on which database I want to work without having to select it before?

Would something like USE federatednotions.gdpr CREATE CONSTRAINT ... work? The constraints need to be added to all the individual parts instead of the composite database linking them together

Well, this was exactly my goal:

when I write USE federatednotions.gdpr I mean a specific database (that is also part of a federated one).

I undesratnd that I MUST use USE GDPR instead.

But the question the still remain:

Can I switch between one database and the other using cypher and without having to switch it manually thru the browser?

TY

You should be able to use the database’s alias too (federatednotions.gdpr). Your screenshot shows the prompt was the composite database when you tried to create the constraint. As you stated, you needed to switch to the actual database in order to execute these type of commands.

I would use the USE clause to switch the database manually when needed. The drop down seems to just be a convenience which does the same. It does it in a new editor, so you need to ensure you move to that editor before executing your commands. I feel this makes it a more error prone approach.

No, that doesn't work.
I don't want to connect different DB together, but I'd like to be able to work in a federatedDB context being able to switch to each context and work on it.
If I am in a federated DB, the ':use' command not always works:

This example is with :use

while this other was with use

Anyway, your solution returns an error:

Note the different error while using :use and use. :slight_smile:

So, it is absolutely not clear how to use safely federated DB's.

Exactly, I'm able to use the composite database too, but not to set constraints and indexes even if I switch manually.

And, by my point of view this is an error.

The name of a database or any of it's aliases must run the same code: it cannot answer that.

Then, look at these fragments:

Here I'm settled on the federatednotions db. I did it using the USE command and the dropdown show the correct DB.

Now, I entered the command USE federatednotions.gdpr and this is the (BAD) result:

I noted the following errors:

  1. I used :USE federatednotions.gdpr with a colon
  2. the query doesn't return the requested data
  3. Queries from this point and forward are using the database federatednotions.gdpras the target.
  4. the database selected in the dropdown is beverages
  5. but the data under the dropdown refers to the gdpr database

More, if I should have used USE without the colon, the result should be erroneous:

  1. if I doesn't include a return it gives an error (i.e. doesn't switch the database)
  2. if I add a return statement it returns nothing.

Finally, I would affirm that:
1) the composite database alias cannot be selected in the dropdown box;
2) The composite database alias cannot be queried in the browser

If a use a python script, can I solve or bypass these errors?

Try removing the ; after the use clause, in Cypher it isn't its own query but parts of a bigger one which is why you get an error when it's the only thing in your query

USE federatednotations.gdpr
CREATE CONSTRAINT ...

From my last reply:

Would something like USE federatednotions.gdpr CREATE CONSTRAINT ... work? The constraints need to be added to all the individual parts instead of the composite database linking them together

Notice how there isn't a ; between the USE and CREATE CONSTRAINT parts but you have one in your screenshot?

You seem to mix/confuse the browser command :use and the Cypher query clause USE, which are not interchangeable.

The :use is the same as using the drop down menu and is executed in browser to switch what database you are connected to. This can not be combined with a Cypher query, it is its own command.

In difference, the USE in Cypher is part of a query which tells the server to re-route this query from the database you are connected to and over to the requested database. This means it cannot be used on its own and need an actual query to follow it (not separated by ; as that separates different queries to be run after each other).

As for your conclusions, you are right that you can't connect directly to the composite database alias by either the drop down menu or the :use command. This is due to them only being available for querying when connected to the composite database they belong to. However, they can be queried when using the USE clause as part of the query itself, as this is how it was designed to be reached.

The documentation for the Cypher USE clause: USE - Cypher Manual

1 Like

In the query, I tried different solutions looking for the one able to run;
But you're right, this solution works: now I'll embed in a most complex query and let you know if I still have problems.

1 Like

Thank you for sharing working together and sharing knowledge