Skip to content

Commit

Permalink
Merge pull request #553 from wesharper/bug-551-too-many-fields
Browse files Browse the repository at this point in the history
Resolves an issue where querying 100+ fields on a relationship causes a pg error
  • Loading branch information
olirice authored Sep 25, 2024
2 parents d79be8d + 474d9f0 commit d04b6d5
Show file tree
Hide file tree
Showing 4 changed files with 618 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@
- bugfix: not null foreign keys referencing tables with RLS are marked as nullable

## master
- bugfix: relational query with more than 100 fields fails
9 changes: 7 additions & 2 deletions src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,12 @@ impl NodeBuilder {
.map(|x| x.to_sql(&quoted_block_name, param_context))
.collect::<Result<Vec<_>, _>>()?;

let object_clause = frags.join(", ");
let object_clause: Vec<String> = frags
.chunks(50)
.map(|chunks| format!("jsonb_build_object({})", chunks.join(", ")))
.collect();

let object_clause_string = object_clause.join(" || ").to_string();

let join_clause = self.table.to_join_clause(
fkey,
Expand All @@ -1300,7 +1305,7 @@ impl NodeBuilder {
"
(
select
jsonb_build_object({object_clause})
{object_clause_string}
from
{quoted_schema}.{quoted_table} as {quoted_block_name}
where
Expand Down
Loading

0 comments on commit d04b6d5

Please sign in to comment.