You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works fine as long as the vector only contains a single basic type. But I want to return more complex types and use array_agg(row(other_id, another_value, ...)). In that case I get the following error:
I also gave Postgres composite types a try and create a my_type type in postgres and use it with array_agg(row(...)::my_type). In that case the error changes into:
The docs look like a Vec<T> of a composite type should be supported, but I cannot get it to work. Would somebody be willing to provide a working example?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a sql query that uses
array_agg
to return multiple values in a single column. The statement is something likeselect id, array_agg(other_id) as other_ids from some_table group by id
The query is stored in a file and executed via
sqlx::query_file_as!(MyStruct, "path/to/query.sql")
. The target struct looks like this:pub struct MyStruct { id: i32, emails: Option<Vec<i32>> }
This works fine as long as the vector only contains a single basic type. But I want to return more complex types and use
array_agg(row(other_id, another_value, ...))
. In that case I get the following error:I also gave Postgres composite types a try and create a
my_type
type in postgres and use it witharray_agg(row(...)::my_type)
. In that case the error changes into:I implemented a struct for
my_type
as described at https://docs.rs/sqlx/0.5.9/sqlx/postgres/types/index.html#composite-types but cannot see any difference. The error just stays the same.The docs look like a
Vec<T>
of a composite type should be supported, but I cannot get it to work. Would somebody be willing to provide a working example?Beta Was this translation helpful? Give feedback.
All reactions