mz_expr/scalar/func/impls/
boolean.rs1use mz_expr_derive::sqlfunc;
11use mz_repr::strconv;
12
13#[sqlfunc(
14 sqlname = "NOT",
15 preserves_uniqueness = true,
16 inverse = to_unary!(Not),
17 is_monotone = true
18)]
19fn not(a: bool) -> bool {
20 !a
21}
22
23#[sqlfunc(
24 sqlname = "boolean_to_text",
25 preserves_uniqueness = true,
26 inverse = to_unary!(super::CastStringToBool),
27 is_monotone = true
28)]
29fn cast_bool_to_string<'a>(a: bool) -> &'a str {
30 match a {
31 true => "true",
32 false => "false",
33 }
34}
35
36#[sqlfunc(
37 sqlname = "boolean_to_nonstandard_text",
38 preserves_uniqueness = true,
39 inverse = to_unary!(super::CastStringToBool),
40 is_monotone = true
41)]
42fn cast_bool_to_string_nonstandard<'a>(a: bool) -> &'a str {
43 strconv::format_bool_static(a)
48}
49
50#[sqlfunc(
51 sqlname = "boolean_to_integer",
52 preserves_uniqueness = true,
53 inverse = to_unary!(super::CastInt32ToBool),
54 is_monotone = true
55)]
56fn cast_bool_to_int32(a: bool) -> i32 {
57 match a {
58 true => 1,
59 false => 0,
60 }
61}
62
63#[sqlfunc(
64 sqlname = "boolean_to_bigint",
65 preserves_uniqueness = true,
66 inverse = to_unary!(super::CastInt64ToBool),
67 is_monotone = true
68)]
69fn cast_bool_to_int64(a: bool) -> i64 {
70 match a {
71 true => 1,
72 false => 0,
73 }
74}