mz_expr/scalar/func/impls/
oid.rs1use mz_ore::cast::ReinterpretCast;
11use mz_pgrepr::Type;
12use mz_repr::adt::system::{Oid, RegClass, RegProc, RegType};
13use mz_repr::strconv;
14
15sqlfunc!(
16 #[sqlname = "oid_to_text"]
17 #[preserves_uniqueness = true]
18 #[inverse = to_unary!(super::CastStringToOid)]
19 fn cast_oid_to_string(a: Oid) -> String {
20 let mut buf = String::new();
21 strconv::format_uint32(&mut buf, a.0);
22 buf
23 }
24);
25
26sqlfunc!(
27 #[sqlname = "oid_to_integer"]
28 #[preserves_uniqueness = true]
29 #[inverse = to_unary!(super::CastInt32ToOid)]
30 fn cast_oid_to_int32(a: Oid) -> i32 {
31 i32::reinterpret_cast(a.0)
38 }
39);
40
41sqlfunc!(
42 #[sqlname = "oid_to_bigint"]
43 #[preserves_uniqueness = true]
44 #[inverse = to_unary!(super::CastInt64ToOid)]
45 fn cast_oid_to_int64(a: Oid) -> i64 {
46 i64::from(a.0)
47 }
48);
49
50sqlfunc!(
51 #[sqlname = "oidtoregclass"]
52 #[preserves_uniqueness = true]
53 #[inverse = to_unary!(super::CastRegClassToOid)]
54 fn cast_oid_to_reg_class(a: Oid) -> RegClass {
55 RegClass(a.0)
56 }
57);
58
59sqlfunc!(
60 #[sqlname = "oidtoregproc"]
61 #[preserves_uniqueness = true]
62 #[inverse = to_unary!(super::CastRegProcToOid)]
63 fn cast_oid_to_reg_proc(a: Oid) -> RegProc {
64 RegProc(a.0)
65 }
66);
67
68sqlfunc!(
69 #[sqlname = "oidtoregtype"]
70 #[preserves_uniqueness = true]
71 #[inverse = to_unary!(super::CastRegTypeToOid)]
72 fn cast_oid_to_reg_type(a: Oid) -> RegType {
73 RegType(a.0)
74 }
75);
76
77sqlfunc!(
78 fn mz_type_name<'a>(oid: Oid) -> Option<String> {
79 if let Ok(t) = Type::from_oid(oid.0) {
80 Some(t.name().to_string())
81 } else {
82 None
83 }
84 }
85);