- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是小鬼的新手,有一个非常简单的案例,我需要检查一下:
g.V().hasLabel("Entity").has("identifier", "123").fold()
.coalesce(
__.unfold(),
__.addV("Entity")
.property("identifier", "123")
.property("value", "A")
.property("action", "add")
)
.property("value", "A")
.property("action", "update")
.iterate();
最佳答案
当您编写 Gremlin 时,您需要从流的角度进行思考。 V()
生成图中所有顶点的流。设想该流中的每个项目点击 hasLabel()
和 has()
过滤器配对,直到它们达到 fold()
的减少步骤产生 List
具有与过滤条件匹配的顶点,或者如果没有,则简单地生成一个空列表,该列表成为流中的新对象。
从那里 coalesce()
产生一种 if-then 类型的情况,其中提供给它的第一个返回值的子流最终被耗尽,其余的子流被忽略。因此,如果 unfold()
这需要 List
顶点由 fold()
生成包含一个顶点,然后将其提供给流并且该顶点存在且 coalesce()
因此生成现有顶点并继续执行 property("value", "A").property("action", "update")
的最后两个步骤.如果List
为空然后 unfold()
流不产生任何对象并转到下一个以 addV()
开头的子流. addV()
流显然会产生一个新的 Vertex
具有指定的属性,然后 coalesce()
因为它的父节点会在流中生成新添加的顶点,它也会继续执行最后两个步骤,从而覆盖您提供给 addV()
的属性值。 .
如果你想有两个单独的路径,那么你可以做这样的事情:
g.V().hasLabel("Entity").has("identifier", "123").fold()
.coalesce((Traversal)
__.unfold()
.property("value", "A")
.property("action", "update"),
__.addV("Entity")
.property("identifier", "123")
.property("value", "A")
.property("action", "add")
)
.iterate();
关于Gremlin - 顶点的 Upsert 不适用于合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61541672/
可写 CTE 被认为是 9.5 之前的 UPSERT 解决方案,如 Insert, on duplicate update in PostgreSQL? 中所述 可以使用以下可写 CTE 惯用法的信息
可写 CTE 被认为是 9.5 之前的 UPSERT 解决方案,如 Insert, on duplicate update in PostgreSQL? 中所述 可以使用以下可写 CTE 惯用法的信息
我正在通过 Python 在我的 MongoDB 上运行更新。我有这一行: self.word_counts[source].update({'date':posttime},{"$inc" : wo
我正在尝试使用 Sequelize 添加将数据创建到我的expressJs 应用程序中的 2 个表中的功能。 Controller : Campaign.upsert({ institutio
我正在尝试用现有的 ngxs 状态运算符替换或插入数组项 (upsert)。我目前正在使用以下 iif 语句。有更简单的方法吗? setState( patch({ contractLis
有没有一种方法可以在发生以下情况的 kdb 中更新插入: 如果键不存在,则插入值 如果key存在,检查当前值是否大于 A) 如果是,则不执行任何操作 B) 如果不是,更新值 类似于: job upse
我正在尝试更新测试键空间和表中的记录。当我插入一条记录时,接受一个列值更改,而另一个不接受。 (注意:尽管没有错误消息,我也无法删除记录) 观察 middle_initial 是如何不更新的,而 ti
我正在寻找一些有关如何优化sql存储过程的建议。 对于第一个查询,我正在执行插入操作,对于第二个查询,我正在进行更新(如果数据存在)。 我想要做的是将两个存储过程合并为一个,查询将检查数据是否存在而不
我有以下两个类(class) 条目 public class Entry { public Guid Id { get; set; } public IEnumerable Data
两年前有人问how to do upserts when you don't know a document's id . (未接受的)答案引用了 feature request 这导致了 _upda
今天这有点令人沮丧。我确定它很简单,我忽略了。请参阅下面的代码(为了示例而简化): def dbUpsert(sqlQuery, sqlValues): # Connect to the da
今天这有点令人沮丧。我确定它很简单,我忽略了。请参阅下面的代码(为了示例而简化): def dbUpsert(sqlQuery, sqlValues): # Connect to the da
我想更新插入(如果不存在则更新插入)我的 sqlite 表中的一些行。 我看到了这个sqlite命令: INSERT OR REPLACE INTO Employee (id, name, role)
我要从Amazon Mechanical Turk中提取一些数据并将其保存在mongodb集合中。 我有多个工作人员重复执行每个任务,因为略有冗余可以帮助我检查工作质量。 每次使用boto AWS p
我正在尝试测试新的 PostgreSQL upsert syntax使用以下测试代码,但出现语法错误: test=> CREATE TABLE test1 ( test(> key1
我正在使用 PostgreSQL v9.6.6。我正在运行以下 SQL: insert into t_vs_config_key (name, description, is_brand_depend
我在为 postgresql 编写强大的 upsert 函数方面得到了很多帮助。我正在尝试将值插入到包含 3 列的表中,其中两列是外键,一列是文本。 我有一个非常相似的函数,效果很好,只是没有像这个函
我在 MySQL 中有一个表,每晚都会通过 cron 任务更新。每一行都被更改,因为我从 XLS 文件获取数据并且必须更新所有值。 首先我的问题是是否值得更新每一行,或者另一方面删除所有行并再次插入。
更新插入在冲突时有效,但 id 的数据类型是串行的,这意味着我想让它自动生成/递增。如果我在不指定 id 的情况下执行插入,则插入工作正常。 我遇到的问题是将两者结合起来。为了让 key 自动递增,我
这个问题在这里已经有了答案: How to UPSERT (MERGE, INSERT ... ON DUPLICATE UPDATE) in PostgreSQL? (7 个答案) 关闭 4 年前
我是一名优秀的程序员,十分优秀!