Skip to content

Commit

Permalink
Exclude full-text search columns from entity queries (#5693)
Browse files Browse the repository at this point in the history
- Remove `tsvector` columns from `SELECT` clauses in entity queries
- Filter out full-text search columns from the list of selected columns

Full-text search columns (`tsvector` type) are used for indexing and
efficient text searching, but they are not part of the entity's data
model and are not meant to be directly queried or returned. This fixes a
bug where trying to load a tsvector column fails, as diesel does not
natively have tsvector support, and we don't explicitly handle the type
in `relational::value::OidValue::from_sql`.
  • Loading branch information
encalypto authored Nov 4, 2024
1 parent b9e1c5f commit fc80657
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion store/postgres/src/relational/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ impl<'a> Table<'a> {
}
};

// NB: Exclude full-text search columns from selection. These columns are used for indexing
// and searching but are not part of the entity's data model.
cols.retain(|c| !c.is_fulltext());

if T::WITH_INTERNAL_KEYS {
match parent_type {
Some(IdType::String) => cols.push(&*PARENT_STRING_COL),
Expand Down Expand Up @@ -346,7 +350,10 @@ impl<'a> Table<'a> {
ColumnType::Int8 => add_field::<BigInt>(&mut selection, self, column),
ColumnType::Timestamp => add_field::<Timestamptz>(&mut selection, self, column),
ColumnType::String => add_field::<Text>(&mut selection, self, column),
ColumnType::TSVector(_) => add_field::<Text>(&mut selection, self, column),
ColumnType::TSVector(_) => {
// Skip tsvector columns in SELECT as they are for full-text search only and not
// meant to be directly queried or returned
}
ColumnType::Enum(_) => add_enum_field(&mut selection, self, column),
};
}
Expand Down

0 comments on commit fc80657

Please sign in to comment.