From 433614e3672c29b3d5da24f115b0d3c736ecefc0 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Wed, 7 Sep 2022 16:47:30 -0700 Subject: [PATCH] store: Handle is type 'Bytes' correctly for children type c We did not account for parent ids being `bytea` when generating queries for children type c which only caused trouble when such entities were used in interfaces. --- store/postgres/src/relational_queries.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index e62de38f14c..c3b435e5eb3 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -1906,6 +1906,7 @@ impl ParentIds { #[derive(Debug, Clone)] enum TableLink<'a> { Direct(&'a Column, ChildMultiplicity), + /// The `Table` is the parent table Parent(&'a Table, ParentIds), } @@ -2190,6 +2191,7 @@ impl<'a> FilterWindow<'a> { fn children_type_c( &self, + parent_primary_key: &Column, child_ids: &[Vec>], limit: ParentLimit<'_>, block: BlockNumber, @@ -2209,7 +2211,7 @@ impl<'a> FilterWindow<'a> { out.push_sql("\n/* children_type_c */ from "); out.push_sql("rows from (unnest("); - out.push_bind_param::, _>(&self.ids)?; + parent_primary_key.bind_ids(&self.ids, out)?; out.push_sql("), reduce_dim("); self.table.primary_key().push_matrix(child_ids, out)?; out.push_sql(")) as p(id, child_ids)"); @@ -2292,9 +2294,13 @@ impl<'a> FilterWindow<'a> { } } } - TableLink::Parent(_, ParentIds::List(child_ids)) => { - self.children_type_c(child_ids, limit, block, &mut out) - } + TableLink::Parent(parent_table, ParentIds::List(child_ids)) => self.children_type_c( + parent_table.primary_key(), + child_ids, + limit, + block, + &mut out, + ), TableLink::Parent(_, ParentIds::Scalar(child_ids)) => { self.child_type_d(child_ids, limit, block, &mut out) }