pgrx_sql_entity_graph/aggregate/
options.rs

1//LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2//LICENSE
3//LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4//LICENSE
5//LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc. <contact@pgcentral.org>
6//LICENSE
7//LICENSE All rights reserved.
8//LICENSE
9//LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10/*!
11
12`#[pg_aggregate]` related options for Rust to SQL translation
13
14> Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15> to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16
17*/
18use crate::{PgrxSql, ToSql};
19
20/// Corresponds to the `PARALLEL` and `MFINALFUNC_MODIFY` in [`CREATE AGGREGATE`](https://www.postgresql.org/docs/current/sql-createaggregate.html).
21#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
22pub enum ParallelOption {
23    Safe,
24    Restricted,
25    Unsafe,
26}
27
28impl ToSql for ParallelOption {
29    fn to_sql(&self, _context: &PgrxSql) -> eyre::Result<String> {
30        let value = match self {
31            ParallelOption::Safe => String::from("SAFE"),
32            ParallelOption::Restricted => String::from("RESTRICTED"),
33            ParallelOption::Unsafe => String::from("UNSAFE"),
34        };
35        Ok(value)
36    }
37}
38
39/// Corresponds to the `FINALFUNC_MODIFY` and `MFINALFUNC_MODIFY` in [`CREATE AGGREGATE`](https://www.postgresql.org/docs/current/sql-createaggregate.html).
40#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
41pub enum FinalizeModify {
42    ReadOnly,
43    Shareable,
44    ReadWrite,
45}
46
47impl ToSql for FinalizeModify {
48    fn to_sql(&self, _context: &PgrxSql) -> eyre::Result<String> {
49        let value = match self {
50            FinalizeModify::ReadOnly => String::from("READ_ONLY"),
51            FinalizeModify::Shareable => String::from("SHAREABLE"),
52            FinalizeModify::ReadWrite => String::from("READ_WRITE"),
53        };
54        Ok(value)
55    }
56}