如何创建具有自己类型字段的CQL类型?

发布于 2025-01-20 23:22:12 字数 263 浏览 4 评论 0原文

我想创建一个狗数据库。我想使用狗类型。狗类型具有“父母”的野外“父母”,可以引用另一只狗,即狗的父母。

我遇到了一个问题,因为此脚本试图定义狗类型,该脚本在其属性父母中引用了自己的类型,但狗类型尚未创建。

CREATE TYPE IF NOT EXISTS dog (
    name text,
    parent frozen<dog>
);

我可以做任何解决方法来保持这种数据结构的方法吗?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法回应 2025-01-27 23:22:12

您不能在其自己的定义中嵌套CQL用户定义的类型,因为它成为圆形引用 - 由于尚未创建嵌套类型,因此无法创建嵌套本身的UDT创建。它在圆圈中四处走动。

附带说明,除非绝对必要,除非它们引入您的数据模型,否则我们通常会阻止使用UDT的使用。此外,嵌套的UDT将复杂性水平提高到更高的水平。

只要可能,请尝试在表中使用本机CQL列以保持简单。就您而言,我看不到为什么您不能将狗的名字作为专栏和狗的父母作为同一张表中的另一列的原因。同样,这使它变得简单,并使其更容易维护。干杯!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文