common_function/system/pg_catalog/
version.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16use std::{env, fmt};
17
18use common_query::error::Result;
19use common_query::prelude::{Signature, Volatility};
20use datatypes::data_type::ConcreteDataType;
21use datatypes::vectors::{StringVector, VectorRef};
22
23use crate::function::{Function, FunctionContext};
24
25#[derive(Clone, Debug, Default)]
26pub(crate) struct PGVersionFunction;
27
28impl fmt::Display for PGVersionFunction {
29    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30        write!(f, crate::pg_catalog_func_fullname!("VERSION"))
31    }
32}
33
34impl Function for PGVersionFunction {
35    fn name(&self) -> &str {
36        crate::pg_catalog_func_fullname!("version")
37    }
38
39    fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result<ConcreteDataType> {
40        Ok(ConcreteDataType::string_datatype())
41    }
42
43    fn signature(&self) -> Signature {
44        Signature::exact(vec![], Volatility::Immutable)
45    }
46
47    fn eval(&self, _func_ctx: &FunctionContext, _columns: &[VectorRef]) -> Result<VectorRef> {
48        let result = StringVector::from(vec![format!(
49            "PostgreSQL 16.3 GreptimeDB {}",
50            env!("CARGO_PKG_VERSION")
51        )]);
52        Ok(Arc::new(result))
53    }
54}