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
// Copyright Materialize, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use pgrepr::Type;
use repr::adt::system::{Oid, RegClass, RegProc, RegType};

use crate::EvalError;

sqlfunc!(
    #[sqlname = "oidtoi32"]
    #[preserves_uniqueness = true]
    fn cast_oid_to_int32(a: Oid) -> i32 {
        a.0
    }
);

sqlfunc!(
    #[sqlname = "oidtoi64"]
    #[preserves_uniqueness = true]
    fn cast_oid_to_int64(a: Oid) -> i64 {
        i64::from(a.0)
    }
);

sqlfunc!(
    #[sqlname = "oidtoregclass"]
    #[preserves_uniqueness = true]
    fn cast_oid_to_reg_class(a: Oid) -> RegClass {
        RegClass(a.0)
    }
);

sqlfunc!(
    #[sqlname = "oidtoregproc"]
    #[preserves_uniqueness = true]
    fn cast_oid_to_reg_proc(a: Oid) -> RegProc {
        RegProc(a.0)
    }
);

sqlfunc!(
    #[sqlname = "oidtoregtype"]
    #[preserves_uniqueness = true]
    fn cast_oid_to_reg_type(a: Oid) -> RegType {
        RegType(a.0)
    }
);

sqlfunc!(
    fn pg_get_constraintdef(_oid: Option<Oid>) -> Result<String, EvalError> {
        Err(EvalError::Unsupported {
            feature: "pg_get_constraintdef".to_string(),
            issue_no: Some(9483),
        })
    }
);

sqlfunc!(
    fn mz_type_name<'a>(oid: Oid) -> Option<String> {
        if let Some(t) = Type::from_oid(oid.0 as u32) {
            Some(t.name().to_string())
        } else {
            None
        }
    }
);