-
-
Notifications
You must be signed in to change notification settings - Fork 296
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hi,
Thanks for this awesome library.
I'm fooling around with custom types.
- This works:
use pgx::prelude::*;
use serde::{Serialize, Deserialize};
pgx::pg_module_magic!();
#[derive(Debug, Serialize, Deserialize, PostgresType)]
pub struct A;
#[pg_extern]
fn myfunc() -> A {
A
}
- However, this does not anymore, when you wrap the return in a
Result
use pgx::prelude::*;
use pgx::spi;
use serde::{Serialize, Deserialize};
pgx::pg_module_magic!();
#[derive(Debug, Serialize, Deserialize, PostgresType)]
pub struct A;
#[pg_extern]
fn myfunc() -> Result<A, spi::Error> {
Ok(A)
}
It compiles fine of course, but when you try to create extension
, you get ERROR: type "a" already exists
. (also, it's not dependent on spi
, changing spi::Error
to std::error::Error
produces the same result).
It seems that this is tied to ordering problems in the generated sql file. Because this also fails with the same error:
use pgx::prelude::*;
use pgx::spi;
use serde::{Serialize, Deserialize};
pgx::pg_module_magic!();
#[derive(Debug, Serialize, Deserialize, PostgresType)]
pub struct B;
#[derive(Debug, Serialize, Deserialize, PostgresType)]
pub struct A;
#[pg_extern]
fn myfunc(_x: B) -> Result<A, spi::Error> {
Ok(A)
}
But, rename struct A
to struct Z
, and it now works!
use pgx::prelude::*;
use pgx::spi;
use serde::{Serialize, Deserialize};
pgx::pg_module_magic!();
#[derive(Debug, Serialize, Deserialize, PostgresType)]
pub struct B;
#[derive(Debug, Serialize, Deserialize, PostgresType)]
pub struct Z;
#[pg_extern]
fn myfunc(_x: B) -> Result<Z, spi::Error> {
Ok(Z)
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working