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
I am using postgres, and I am making a query like this:
use chrono::{DateTime,Utc};use ormx::{Patch,Table};use serde::{Deserialize,Serialize};use sqlx::{FromRow,Type};#[derive(Debug,Table,Clone,Serialize,Type,FromRow)]#[ormx(table = "tags", id = id, insertable, deletable)]pubstructTag{#[ormx(default)]pubid:i32,pubname:String,pubupdated_at:DateTime<Utc>,}#[derive(Debug,Clone,Serialize,FromRow)]pubstructTaskEntity{pubtags:Option<Vec<Tag>>,}implTaskEntity{pubasyncfnall_by_gid(pool:&Pool<Postgres>,gid:u32) -> Result<Vec<TaskEntity>,Error>{
sqlx::query_as!(TaskEntity, r#" select array_agg(tags.*) as "tags: Vec<Tag>" from tasks_tags join tags on tasks_tags.tag_id = tags.id "#).fetch_all(pool).await}}
And then I got an error like this:
thread 'actix-rt|system:0|arbiter:0' panicked at 'internal error: entered unreachable code: (bug) use of unresolved type declaration [oid=22100]', /home/hugosum/.cache/cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-core-0.5.9/src/postgres/type_info.rs:746:17
I have then tried to change the type to String like this:
#[derive(Debug,Clone,Serialize,FromRow)]pubstructTaskEntity{pubtags:Option<Vec<String>>,}implTaskEntity{pubasyncfnall_by_gid(pool:&Pool<Postgres>,gid:u32) -> Result<Vec<TaskEntity>,Error>{
sqlx::query_as!(TaskEntity, r#" select array_agg(tags.*) as "tags: Vec<String>" from tasks_tags join tags on tasks_tags.tag_id = tags.id "#).fetch_all(pool).await}}
And it would work if I just get a single field with String:
#[derive(Debug,Clone,Serialize,FromRow)]pubstructTaskEntity{pubtags:Option<Vec<String>>,}implTaskEntity{pubasyncfnall_by_gid(pool:&Pool<Postgres>,gid:u32) -> Result<Vec<TaskEntity>,Error>{
sqlx::query_as!(TaskEntity, r#" select array_agg(tags.name) as "tags: Vec<String>" from tasks_tags join tags on tasks_tags.tag_id = tags.id "#).fetch_all(pool).await}}
So I suspect the issue is with the composite type created by array_agg. Is there any workaround right now?
database schema as a reference:
CREATETYPEstatusAS ENUM ('completed', 'incomplete');
droptable if exists tasks;
createtableif not exists tasks(
id int GENERATED ALWAYS AS IDENTITY,
name varchar(256) not null,
-- created_at timestamptz not null,
updated_at timestamptznot null,
status status not null,
primary key(id)
);
droptable if exists tags;
createtableif not exists tags(
id int GENERATED ALWAYS AS IDENTITY,
name varchar(256) not null,
updated_at timestamptznot null,
primary key(id)
);
droptable if exists tasks_tags;
createtableif not exists tasks_tags(
id int GENERATED ALWAYS AS IDENTITY,
task_id intnot null,
tag_id intnot null,
primary key(id),
foreign key(task_id) references tasks ON DELETE CASCADE,
foreign key(tag_id) references tags ON DELETE CASCADE
);
The text was updated successfully, but these errors were encountered:
I am using postgres, and I am making a query like this:
And then I got an error like this:
I have then tried to change the type to
String
like this:And got this error this time:
And it would work if I just get a single field with
String
:So I suspect the issue is with the composite type created by
array_agg
. Is there any workaround right now?database schema as a reference:
The text was updated successfully, but these errors were encountered: