I want to create a dog database. I want to use dog types. Dog types have a field 'parent', that can reference another dog, the dog's parent.
I'm running into an issue because this script tries to define the dog type, that references its own type in its property parent, but the dog type isn't created yet.
CREATE TYPE IF NOT EXISTS dog (
name text,
parent frozen<dog>
);
Anything I can do as a workaround to keep this data structure?
Thanks.
You cannot nest a CQL user-defined type within its own definition because it becomes a circular reference -- the creation of a UDT which nests itself cannot be created because the nested type does not exist because it hasn't been created yet. It's going around in circles.
As a side note, we generally discourage the use of UDTs unless absolutely necessary due to the level of complexity they introduce to your data model. Moreover, nested UDTs increase the level of complexity to a higher level.
Whenever possible, try to use native CQL columns in tables to keep it simple. In your case, I can't see a reason why you couldn't have a dog's name as a column and the dog's parent as another column in the same table. Again, this keeps it simple and makes it easier to maintain. Cheers!