Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #1301 #1302

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pgrx-sql-entity-graph/src/pg_extern/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,17 @@ impl ToSql for PgExternEntity {
Err(err) => return Err(err.into()),
};

let schema = self
.schema
.map(|schema| format!("{}.", schema))
.unwrap_or_else(|| context.schema_prefix_for(&self_index));

eprintln!("schema={schema}");
let operator_sql = format!("\n\n\
-- {file}:{line}\n\
-- {module_path}::{name}\n\
CREATE OPERATOR {opname} (\n\
\tPROCEDURE=\"{name}\",\n\
CREATE OPERATOR {schema}{opname} (\n\
\tPROCEDURE={schema}\"{name}\",\n\
\tLEFTARG={schema_prefix_left}{left_arg}, /* {left_name} */\n\
\tRIGHTARG={schema_prefix_right}{right_arg}{maybe_comma} /* {right_name} */\n\
{optionals}\
Expand Down
1 change: 1 addition & 0 deletions pgrx-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod name_tests;
mod numeric_tests;
mod pg_extern_tests;
mod pg_guard_tests;
mod pg_operator_tests;
mod pg_try_tests;
mod pgbox_tests;
mod pgrx_module_qualification;
Expand Down
35 changes: 35 additions & 0 deletions pgrx-tests/src/tests/pg_operator_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
//LICENSE
//LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
//LICENSE
//LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc. <contact@pgcentral.org>
//LICENSE
//LICENSE All rights reserved.
//LICENSE
//LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
use pgrx::prelude::*;

#[pg_schema]
mod pg_catalog {
use pgrx::{opname, pg_operator};

#[pg_operator]
#[opname(==>)]
fn concat_strings(left: String, right: String) -> String {
left + &right
}
}

#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
mod tests {
#[allow(unused_imports)]
use crate as pgrx_tests;
use pgrx::prelude::*;

#[pg_test]
fn test_correct_schema() {
let result = Spi::get_one::<String>("SELECT 'hello, ' OPERATOR(pg_catalog.==>) 'world';");
assert_eq!(result, Ok(Some(String::from("hello, world"))));
}
}