BSON_ EXTRACT_ BOOL
On this page
Extracts the boolean value for the specified key from the BSON data, converts it to the SingleStore TINYINT
type, and returns the value.
Syntax
BSON_EXTRACT_BOOL(<input> [, path_key_1, path_key_2,.., path_key_n])
Arguments
-
<input>
: A valid BSON document or an expression that evaluates to a valid BSON document. -
<path>
: A comma-separated list of dictionary keys or array positions (zero-based index).
Return Type
SingleStore TINYINT
type.
Remarks
The following table specifies the value returned by BSON_
for each input value:
Input Value |
Output Value |
---|---|
BSON boolean |
1 |
BSON boolean |
0 |
BSON |
|
Any other value or a non-boolean BSON type |
|
Examples
Note: The following examples explicitly cast string to BSON for clarity.
The following examples extract a boolean value:
SELECT BSON_EXTRACT_BOOL('{"a":{"b":true}}':>BSON, 'a', 'b') AS Result;
+--------+
| Result |
+--------+
| 1 |
+--------+
SELECT BSON_EXTRACT_BOOL('{"a":{"b":false}}':>BSON, 'a', 'b') AS Result;
+--------+
| Result |
+--------+
| 0 |
+--------+
Last modified: April 2, 2024