mz_expr/scalar/func/impls/
char.rs1use mz_expr_derive::sqlfunc;
11use mz_repr::SqlScalarType;
12use mz_repr::adt::char::{Char, CharLength, format_str_pad};
13use serde::{Deserialize, Serialize};
14
15#[derive(
19 Ord,
20 PartialOrd,
21 Clone,
22 Debug,
23 Eq,
24 PartialEq,
25 Serialize,
26 Deserialize,
27 Hash
28)]
29pub struct PadChar {
30 pub length: Option<CharLength>,
31}
32
33#[sqlfunc(
34 PadChar,
35 sqlname = "padchar",
36 output_type_expr = SqlScalarType::Char { length: self.length }.nullable(input_type.nullable)
37)]
38fn pad_char<'a>(&self, a: &'a str) -> Char<String> {
39 Char(format_str_pad(a, self.length))
40}
41
42#[sqlfunc(
45 sqlname = "char_to_text",
46 preserves_uniqueness = true,
47 is_eliminable_cast = true,
48 inverse = super::CastStringToChar{
49 length: None,
50 fail_on_len: false,
51 }
52)]
53fn cast_char_to_string<'a>(a: Char<&'a str>) -> &'a str {
54 a.0
55}