带有子查询的N1QL更新文档

问题描述 投票:0回答:1

我正在尝试使用与另一个“地区”文档的“名称”相对应的“地区名称”字段对“国家”文档进行非规范化。我的N1QL查询如下,但不起作用

update test as t1 set regionName = (
 select raw name from test as t2 where `_class`="Region"
) where `_class`="Country" and t1.regionCode=t2.code RETURNING *;

有帮助吗?

couchbase n1ql
1个回答
0
投票

N1QL没有UPDATE JOINS。您不能在WHERE子句中使用SET CLAUSE子查询源。

使用合并

MERGE test AS m 
USING test AS s
ON s.`_class`="Region" AND m.`_class`="Country" AND m.regionCode=s.code
WHEN MATCHED THEN m.regionName = s.name;

https://blog.couchbase.com/query-json-sql-couchbase-query-workbench-coffee-on-couchbase/

© www.soinside.com 2019 - 2024. All rights reserved.