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