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

Postgres REGCLASS is not convertible to rust native Strings #1135

Open
uds5501 opened this issue May 1, 2024 · 1 comment
Open

Postgres REGCLASS is not convertible to rust native Strings #1135

uds5501 opened this issue May 1, 2024 · 1 comment

Comments

@uds5501
Copy link

uds5501 commented May 1, 2024

Overview:

It seems that postgres "regclass" is not convertible to native rust strings.

Triage:

I was trying to fetch an array of columns for a table where primary keys are indexed using the following snippet:

    // ... some function above
    let table_indexed_attributes_query = r#"
        SELECT array_agg(a.attname)
        FROM   pg_index i
        JOIN   pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
        WHERE  i.indrelid = $1::regclass
        AND    i.indisprimary;
    "#;

    let result_indexed_attributes = client.borrow_mut().query(table_indexed_attributes_query, &[&table_name]).unwrap();
    let indexed_attributes = match result_indexed_attributes.get(0) {
        Some(indexed_attributes) => {
            let data: String = indexed_attributes.get(0);
            let indexed_columns = data.split(",")
                .map(|s| s.to_string())
                .collect();
            indexed_columns
        }
        None => vec![],
    };

While running, I am getting the following error:

called `Result::unwrap()` on an `Err` value: Error { kind: ToSql(0), cause: Some(WrongType { postgres: Regclass, rust: "alloc::string::String" }) }
image

Question:

While I can't convert regclass to String, is there any rust native object I could convert it into? If not, I'd like to help build support for this.

@uds5501
Copy link
Author

uds5501 commented May 2, 2024

Apologies: I noticed that the issue not the conversation from regclass to String, rather it's the other way around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant