After upgrading to Couchbase 4.5 I have started getting this error "Expression must be a group key or aggregate (write
.timestamp
)","code":4210}. I'm i doing something wrong here? here is my query
在升级到Couchbase 4.5之后,我开始得到这个错误“表达式必须是组键或聚合(write.timestamp)”、“代码”:4210}。我做错什么了吗?这是我的查询
select max(timestamp) as lastDetect, count(timestamp) as detectCount from write where docType is not missing AND docType = 'DetectRecord' AND proximityUUID = $uuid AND major = $major AND minor = $minor AND timestamp BETWEEN $startTime AND $endTime ORDER BY timestamp desc limit 1;
选择max(timestamp)作为lastDetect, count(timestamp)作为detectCount从没有缺少docType的写入,docType = 'DetectRecord', proximityUUID = $uuid, major和minor = $minor, $startTime和$endTime ORDER之间的时间戳,按时间戳desc limit 1;
Example document:
示例文档:
{ "id": "1234k", "docType": "DetectRecord", "proximityUUID": "12kdf", "major": "dkf", "minor": "ad", "timestamp": 1464954200000 }
{"id": "1234k", "docType": "DetectRecord", "proximityUUID": "12kdf", "major": "dkf", "minor": "ad", "timestamp": 1464954200000}
2 个解决方案
#1
1
Yes Marquis, N1QL enforces the correct GROUP BY syntax/semantics in 4.5. This is mentioned in release notes "behavior changes": http://developer.couchbase.com/documentation/server/4.5/release-notes/relnotes.html
是的,在4.5中,N1QL通过语法/语义强制执行正确的组。发布说明“行为改变”中提到了这一点:http://developer.couchbase.com/documentation/server/4.5/ reletes/relnotes.html
#2
1
This was caused by a change added to couchbase 4.5 (http://developer.couchbase.com/documentation/server/4.5/release-notes/relnotes.html). Changing the query to the following resolved this for me.
这是由添加到couchbase 4.5 (http://developer.couchbase.com/documentation/server/4.5 release-notes/relnotes.html)的更改引起的。将查询更改为以下为我解决了这个问题。
select max(timestamp) as lastDetect, count(timestamp) as detectCount
from write
where docType is not missing AND docType = 'DetectRecord' AND proximityUUID = $uuid AND major = $major AND minor = $minor AND timestamp BETWEEN $startTime AND $endTime
GROUP BY timestamp
ORDER BY timestamp desc limit 1;
#1
1
Yes Marquis, N1QL enforces the correct GROUP BY syntax/semantics in 4.5. This is mentioned in release notes "behavior changes": http://developer.couchbase.com/documentation/server/4.5/release-notes/relnotes.html
是的,在4.5中,N1QL通过语法/语义强制执行正确的组。发布说明“行为改变”中提到了这一点:http://developer.couchbase.com/documentation/server/4.5/ reletes/relnotes.html
#2
1
This was caused by a change added to couchbase 4.5 (http://developer.couchbase.com/documentation/server/4.5/release-notes/relnotes.html). Changing the query to the following resolved this for me.
这是由添加到couchbase 4.5 (http://developer.couchbase.com/documentation/server/4.5 release-notes/relnotes.html)的更改引起的。将查询更改为以下为我解决了这个问题。
select max(timestamp) as lastDetect, count(timestamp) as detectCount
from write
where docType is not missing AND docType = 'DetectRecord' AND proximityUUID = $uuid AND major = $major AND minor = $minor AND timestamp BETWEEN $startTime AND $endTime
GROUP BY timestamp
ORDER BY timestamp desc limit 1;