grafbase_sql_ast/ast/function/
average.rs

1use super::Function;
2use crate::ast::{Column, FunctionType};
3
4/// A representation of the `AVG` function in the database.
5#[derive(Debug, Clone, PartialEq)]
6pub struct Average<'a> {
7    pub(crate) column: Column<'a>,
8}
9
10/// Calculates the average value of a numeric column.
11pub fn avg<'a, C>(col: C) -> Function<'a>
12where
13    C: Into<Column<'a>>,
14{
15    let fun = Average { column: col.into() };
16    fun.into()
17}
18
19impl<'a> From<Average<'a>> for Function<'a> {
20    fn from(value: Average<'a>) -> Self {
21        Self {
22            typ_: FunctionType::Average(value),
23            alias: None,
24        }
25    }
26}