BSON_EXTRACT_BOOL

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_EXTRACT_BOOL() for each input value:

Input Value

Output Value

BSON boolean true

1

BSON boolean false

0

BSON NULL

NULL

Any other value or a non-boolean BSON type

NULL

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

Was this article helpful?