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

"Records like structs" #1458

Open
workingjubilee opened this issue Jan 2, 2024 · 4 comments
Open

"Records like structs" #1458

workingjubilee opened this issue Jan 2, 2024 · 4 comments
Labels
rust+sql Interop between Rust and SQL sql-gen

Comments

@workingjubilee
Copy link
Member

If I'm going to suffer through the implementation of so many accursed macros, then implementing returning a composite type should be as simple as

#[pg_extern]
fn returns_my_composite_type() -> RetType {
    todo!()
}

#[derive(PgRecord)]
struct RetType {
   field_0: i32,
   field_1: String,
}

This much pain and effort to create a sound library is only worth it if the results are
PURE
MAGIC.

Allowing grodier, "lower-level" handling also is fine, too, but that should be the default.

@workingjubilee workingjubilee added sql-gen rust+sql Interop between Rust and SQL labels Jan 2, 2024
@workingjubilee
Copy link
Member Author

For cases where the fields use characters that aren't acceptable in Rust identifiers, or the type has such a name, I think the style where you offer #[pgrx(rename = "name")] is more "to the point" than our current implementation.

@workingjubilee
Copy link
Member Author

The main problem with this is that composite types can be dynamically redefined at runtime, adding or subtracting fields. However, that doesn't particularly seem like a meaningful concern for composite types that are defined by the extension itself, as then the logical expectation is that if you redefine something in the extension, you rebuild the extension. Trying to have an implementation that unites both the "external" composite type and the "internal" composite type cases seamlessly, when those are significantly different to actually interact with, is slightly problematic.

@workingjubilee
Copy link
Member Author

( obviously we should panic if we can't satisfy the deserialization request anymore. )

@workingjubilee
Copy link
Member Author

So, unless something changed in Postgres 16 or Postgres 17, composite types can be changed at runtime but it's a pain in the ass to do because Postgres will issue an error if the composite type is actually used as a column anywhere (since that requires rebuilding the column, basically).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust+sql Interop between Rust and SQL sql-gen
Projects
None yet
Development

No branches or pull requests

1 participant