Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Couchbase N1QL使用子查询更新文档_Couchbase_N1ql - Fatal编程技术网

Couchbase N1QL使用子查询更新文档

Couchbase N1QL使用子查询更新文档,couchbase,n1ql,Couchbase,N1ql,我正在尝试对一个“国家”文档进行非规范化,其中“regionName”字段对应于另一个“Region”文档的“name”。我的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 *; 有什么帮助吗?N

我正在尝试对一个“国家”文档进行非规范化,其中“regionName”字段对应于另一个“Region”文档的“name”。我的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 *;

有什么帮助吗?

N1QL没有更新联接。不能在UPDATE WHERE子句中使用SET子句子查询源

使用合并

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;

CB 6.0

MERGE test AS m 
USING  (SELECT META(c).id, r.name
        FROM test AS r
        JOIN test AS c 
        ON r.`_class`="Region" AND c.`_class`="Country" 
           AND r.regionCode = c.code) AS s
ON KEY s.id
WHEN MATCHED THEN m.regionName = s.name;