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

pg_schema doesn't work with pg_operator #1301

Closed
neilyio opened this issue Sep 18, 2023 · 5 comments
Closed

pg_schema doesn't work with pg_operator #1301

neilyio opened this issue Sep 18, 2023 · 5 comments
Assignees
Labels
bug Something isn't working merged-ready-to-release

Comments

@neilyio
Copy link

neilyio commented Sep 18, 2023

It doesn't seem like pgrx is creating pg_operator functions according topg_schema. I'm able to reproduce this with a minimal pgrx setup, where I try to define an operator in a pg_catalog module to make it available in the global Postgres namespace.

Setup with:

cargo pgrx new pgrx-repro

Set schema to repro in rgrx_repro.control:

comment = 'pgrx_repro:  Created by pgrx'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/pgrx_repro'
relocatable = false
superuser = true
schema = repro

In src/lib.rs, add the following:

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

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

Test with cargo pgrx run --pgcli:

pgrx_repro> create extension pgrx_repro;
CREATE EXTENSION

pgrx_repro> select 'hello' ==> 'world'
operator does not exist: unknown ==> unknown
LINE 1: select 'hello' ==> 'world'
                       ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

pgrx_repro> SELECT set_config('search_path', 'repro,'||current_setting('search_path'), false);
+-----------------------+
| set_config            |
|-----------------------|
| repro,"$user", public |
+-----------------------+
SELECT 1

pgrx_repro> select 'hello' ==> 'world'
+------------+
| ?column?   |
|------------|
| helloworld |
+------------+
SELECT 1

I expected the ==> operator to be available right after create extension pgrx_repro;

@eeeebbbbrrrr
Copy link
Contributor

Hey thanks. Could you include the output of cargo pgrx schema for this too?

@eeeebbbbrrrr eeeebbbbrrrr self-assigned this Sep 18, 2023
@eeeebbbbrrrr eeeebbbbrrrr added the bug Something isn't working label Sep 18, 2023
@neilyio
Copy link
Author

neilyio commented Sep 18, 2023

Sure thing. cargo pgrx schema below:

/* 
This file is auto generated by pgrx.

The ordering of items is not stable, it is driven by a dependency graph.
*/

-- src/lib.rs:6
-- pgrx_repro::hello_pgrx_repro
CREATE  FUNCTION repro."hello_pgrx_repro"() RETURNS TEXT /* &str */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'hello_pgrx_repro_wrapper';

-- src/lib.rs:16
-- pgrx_repro::pg_catalog::concat_strings
CREATE  FUNCTION pg_catalog."concat_strings"(
	"left" TEXT, /* alloc::string::String */
	"right" TEXT /* alloc::string::String */
) RETURNS TEXT /* alloc::string::String */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'concat_strings_wrapper';

-- src/lib.rs:16
-- pgrx_repro::pg_catalog::concat_strings
CREATE OPERATOR ==> (
	PROCEDURE="concat_strings",
	LEFTARG=TEXT, /* alloc::string::String */
	RIGHTARG=TEXT /* alloc::string::String */
);

@eeeebbbbrrrr
Copy link
Contributor

yup, sure enough. we get the function in the right schema but not the operator. dang.

I'll look into this today. Thanks for the report.

eeeebbbbrrrr added a commit to eeeebbbbrrrr/pgrx that referenced this issue Sep 18, 2023
@eeeebbbbrrrr
Copy link
Contributor

there's a fix for this up in #1302.

We'll get it merged and committed soon.

eeeebbbbrrrr added a commit that referenced this issue Sep 19, 2023
This fixes issue #1301 such that the schema generator now
schema-qualifies the operator name when generating a `CREATE OPERATOR`
statement. It also qualifies the associated function.

This allows us to pick up the fact that a `#[pg_operator]` annotation
was applied to function in a module with `#[pg_schema]`.
eeeebbbbrrrr added a commit that referenced this issue Sep 19, 2023
This fixes issue #1301 such that the schema generator now
schema-qualifies the operator name when generating a `CREATE OPERATOR`
statement. It also qualifies the associated function.

This allows us to pick up the fact that a `#[pg_operator]` annotation
was applied to function in a module with `#[pg_schema]`.
@workingjubilee
Copy link
Member

Released in v0.10.2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working merged-ready-to-release
Projects
None yet
Development

No branches or pull requests

3 participants