You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/n1ql/pages/n1ql-language-reference/sequenceops.adoc
+31-4Lines changed: 31 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,7 +187,7 @@ INSERT INTO bookings
187
187
====
188
188
189
189
[[ex-nextval-key]]
190
-
.Insert a sequential value in a document key
190
+
.Insert a sequential value in a document key and body
191
191
====
192
192
The following statement uses the `ordNum` sequence to generate the document key and a booking number within the body of the document.
193
193
@@ -200,6 +200,12 @@ INSERT INTO bookings
200
200
RETURNING META().id, *;
201
201
----
202
202
203
+
This query gives different results, depending on the version of Couchbase Server.
204
+
205
+
'''
206
+
207
+
[.status]##Couchbase Server 7.6–7.6.3##
208
+
203
209
.Results
204
210
[source,json]
205
211
----
@@ -214,12 +220,33 @@ INSERT INTO bookings
214
220
]
215
221
----
216
222
217
-
Since the key is not part of the document, the query has incremented the sequence twice.
218
-
This gives a different sequence number for the document key and the document value, which may not be what you want.
223
+
In versions of Couchbase Server prior to 7.6.4, the key is not regarded as part of the document, so this query increments the sequence twice.
224
+
This gives a different sequence number for the document key and the document value.
225
+
226
+
'''
227
+
228
+
[.status]#Couchbase Server 7.6.4#
229
+
230
+
.Results
231
+
[source,json]
232
+
----
233
+
[
234
+
{
235
+
"id": "1001",
236
+
"bookings": {
237
+
"num": 1001,
238
+
"user": 1
239
+
}
240
+
}
241
+
]
242
+
----
243
+
244
+
In Couchbase Server 7.6.4 and later, the entire VALUES clause (key, value, and options) is regarded as a single document, so the query only increments the sequence once.
245
+
This gives the same sequence number in the document key and the document value.
219
246
====
220
247
221
248
[[ex-nextval-same]]
222
-
.Insert the same sequential value in a document key and body
249
+
.Insert a sequential value with INSERT SELECT
223
250
====
224
251
The following statement uses an INSERT SELECT statement.
225
252
With this query, the document key and document value are both generated within the same document.
0 commit comments