SQL++ for Mobile and Server Differences
|
N1QL is Couchbase’s implementation of the developing SQL++ standard. As such the terms N1QL and SQL++ are used interchangeably in all Couchbase documentation unless explicitly stated otherwise. |
There are several minor but notable behavior differences between SQL++ for Mobile queries and SQL++ for Server, as shown in Table 1.
In some instances, if required, you can force SQL++ for Mobile to work in the same way as SQL++ for Server. These instances are noted in the content below.
Table 1. SQL++ Query Comparison
| Feature | SQL++ for Server | SQL++ for Mobile |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Allows |
Allows |
|
All three are supported (with |
Not supported |
|
Both |
Only |
|
Can compare either complex values or scalar values. |
Only scalar values may be compared. |
|
Result sequencing is based on specific rules described in SQL++ for Server |
Result sequencing is based on the SQLite ordering described in SQLite select overview. |
|
Supported |
|
|
Supported |
Not Supported |
|
Supported |
Not Supported |
Boolean Logic Rules
SQL++ for Server
Couchbase Server operates in the same way as Couchbase Lite, except:
-
MISSING,NULLandFALSEareFALSE -
Numbers
0isFALSE -
Empty strings, arrays, and objects are
FALSE -
All other values are
TRUE
You can choose to use Couchbase Server’s SQL++ rules by using the
TOBOOLEAN(expr) function to convert a value to its boolean value.
SQL++ for Mobile
SQL++ for Mobile’s boolean logic rules are based on SQLite’s, so:
-
TRUEisTRUE, andFALSEisFALSE -
Numbers
0or0.0areFALSE -
Arrays and dictionaries are
FALSE -
String and Blob are
TRUEif the values are casted as a non-zero orFALSEif the values are casted as0or0.0- see: SQLITE’s CAST and Boolean expressions for more details. -
NULLisFALSE -
MISSINGisMISSING
Logical Operations
In SQL++ for Mobile logical operations will return one of three possible values;
TRUE, FALSE, or MISSING.
Logical operations with the MISSING value could result in TRUE or FALSE if
the result can be determined regardless of the missing value, otherwise the
result will be MISSING.
In SQL++ for Mobile - unlike SQL++ for Server - NULL is implicitly converted
to FALSE before evaluating logical operations. Table 2 summarizes the
result of logical operations with different operand values and also shows where
the Couchbase Server behavior differs.
Table 2. Logical Operations Comparison
Operand |
Operand |
SQL ++ for Mobile |
SQL ++ for Mobile |
SQL ++ for Server |
SQL ++ for Server |
|
|
|
|
- |
- |
|
|
|
- |
- |
|
|
|
|
|
- |
|
|
|
|
- |
- |
|
|
|
|
|
- |
- |
|
|
|
- |
- |
|
|
|
|
- |
|
|
|
|
|
- |
- |
|
|
|
|
|
|
- |
|
|
|
- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- |
- |
|
|
|
- |
- |
|
|
|
|
|
|
|
|
|
|
- |
- |
CRUD Operations
-
SQL++ for Mobile only supports Read or Query operations.
-
SQL++ for Server fully supports CRUD operation.
Functions
Division Operator
| SQL ++ for Server | SQL++ for Mobile |
|---|---|
SQL++ for Server always performs float division regardless of the types of the operands. |
The operand types determine the division operation performed. |
Round Function
| SQL ++ for Server | SQL++ for Mobile |
|---|---|
SQL++ for Server |
The |