Important

Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.

BSON_EXTRACT_BOOL

The BSON_EXTRACT_BOOL() function 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:

Was this article helpful?