查询:AQL:变量“$OLD”被多次赋值
Posted
技术标签:
【中文标题】查询:AQL:变量“$OLD”被多次赋值【英文标题】:Query: AQL: variable '$OLD' is assigned multiple times 【发布时间】:2021-12-18 22:03:28 【问题描述】:我想在嵌套循环中更新以下数据。这样做时,我需要从上层循环中获取数据。我通过剪切它来发送数据。还有更多的嵌套数组。当我尝试从父循环中获取数据时,出现以下错误。我尝试了很多变体,例如当我尝试返回时它工作正常,但它不会让我在 UPSERT 中使用它。就这样
数据:
[
"I": 28,
"C": [
"I": 50,
"L": [
"I": 1783,
"E": [
"I": 5107194
,
"I": 5184134
,
"I": 5030548
,
"I": 5069351
]
]
]
]
工作正常:
FOR sport IN $data
FOR country IN sport.C
FOR league IN country.L
UPSERT I: league.I
INSERT I: league.I, C: country.I, S: sport.I
UPDATE I: league.I, C: country.I, S: sport.I IN leagues
FOR event IN league.E
RETURN
I: event.I,
L: league.I
(解析时):
FOR sport IN $data
FOR country IN sport.C
FOR league IN country.L
UPSERT I: league.I
INSERT I: league.I, C: country.I, S: sport.I
UPDATE I: league.I, C: country.I, S: sport.I IN leagues
FOR event IN league.E
UPSERT I: event.I
INSERT
I: event.I,
L: league.I
UPDATE
I: event.I,
L: league.I
IN events
正如我所说,有更多的数组相互嵌套。我该如何解决这个问题?
【问题讨论】:
【参考方案1】:您可以将第一个 UPSERT 放在这样的子查询中:
FOR sport IN $data
FOR country IN sport.C
FOR league IN country.L
LET dummy = (
UPSERT I: league.I
INSERT I: league.I, C: country.I, S: sport.I
UPDATE I: league.I, C: country.I, S: sport.I IN leagues
)
FOR event IN league.E
UPSERT I: event.I
INSERT
I: event.I,
L: league.I
UPDATE
I: event.I,
L: league.I
IN events
这样,第一个 UPSERT 引入的隐式 $OLD 变量的范围仅限于该子查询,因此不会与第二个 UPSERT 冲突。
【讨论】:
以上是关于查询:AQL:变量“$OLD”被多次赋值的主要内容,如果未能解决你的问题,请参考以下文章
verilog设计中,当对同一个被赋值目标同时进行2次或多次赋值时,怎样来决定被赋值目标的有效值?