Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport for Postgres composite types #1732
Comments
This comment has been minimized.
ebkalderon
commented
May 25, 2018
•
|
EDIT: Sorry, I had to edit the example to make sure it was correct and showcased the problem more visibly. I decided to use a more complex composite type to demonstrate the problem. |
This comment has been minimized.
Supporting composite types on Postgres side should work the same way like supporting custom enum types there. Documentation is sparse because nobody have written something about that yet. (Presumably because at most only a few people have tried that Regarding to the example code: (There are several small error in there pointed out by the compiler, I will not attempt to fix them here, just apply the compiler suggesting )
impl ToSql<DbEntry, Pg> for Entry {
fn to_sql<W: Write>(&self, out: &mut serialize::Output<W, Pg>) -> serialize::Result {
ToSql::<sql_types::Integer, Pg>::to_sql(&1, out)?;
ToSql::<sql_types::Oid, Pg>::to_sql(&1700, out)?;
ToSql::<sql_types::Integer, Pg>::to_sql(&/*Somehow figure out the size here*/, out)?;
ToSql::<sql_types::Decimal, Pg>::to_sql(&self.amount, out)?;
ToSql::<sql_types::Oid, Pg>::to_sql(&2950, out)?;
ToSql::<sql_types::Integer, Pg>::to_sql(&16, out)?;
ToSql::<sql_types::Uuid, Pg>::to_sql(&self.currency, out)?;
Ok(IsNull::No)
}
}The (I will close this issue because this is nothing actionable for diesel itself. Feel free to response here, or even better move to our Gitter channel.) |
weiznich
closed this
May 25, 2018
This comment has been minimized.
|
You should also be able to send an anonymous record which gets coerced automatically (but this will transmit as |
This comment has been minimized.
ebkalderon
commented
May 26, 2018
|
These are some excellent responses! Thank you both so much. I will look further into how the |
ebkalderon commentedMay 25, 2018
•
edited
Setup
Versions
Feature Flags
["postgres", "extra"]Problem Description
Hello everyone! I know that Diesel supports defining custom enum types as well as Rust-side newtypes via
diesel-derive-newtype. I am trying to understand whether Diesel supports user-defined newtypes and composite types on the Postgres side as well; the documentation is particularly sparse on this subject.What are you trying to accomplish?
I am currently trying to map a user-defined composite type from Postgres to a Rust struct using Diesel. Some of these composite types are essentially newtypes with a single field, and others have multiple fields. I would like to be able to insert and query these composite types into and from Postgres.
What is the expected output?
N/A
What is the actual output?
When my
insert_intoquery is turned into a string withdebug_query, I see the following:This generated SQL looks pretty good to me. However, the insert fails and returns the following error:
Are you seeing any additional errors?
No, everything else seems to work fine.
Steps to reproduce
Below is a reduced and redacted form of the codebase I'm working on. I am using a struct with multiple fields for the sake of demonstrating the problem more thoroughly.
This is the database migration script I have in place.
Checklist