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
}
}
);