Skip to content

Commit d04b6d5

Browse files
authored
Merge pull request #553 from wesharper/bug-551-too-many-fields
Resolves an issue where querying 100+ fields on a relationship causes a pg error
2 parents d79be8d + 474d9f0 commit d04b6d5

File tree

4 files changed

+618
-2
lines changed

4 files changed

+618
-2
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@
8989
- bugfix: not null foreign keys referencing tables with RLS are marked as nullable
9090

9191
## master
92+
- bugfix: relational query with more than 100 fields fails

src/transpile.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,12 @@ impl NodeBuilder {
12871287
.map(|x| x.to_sql(&quoted_block_name, param_context))
12881288
.collect::<Result<Vec<_>, _>>()?;
12891289

1290-
let object_clause = frags.join(", ");
1290+
let object_clause: Vec<String> = frags
1291+
.chunks(50)
1292+
.map(|chunks| format!("jsonb_build_object({})", chunks.join(", ")))
1293+
.collect();
1294+
1295+
let object_clause_string = object_clause.join(" || ").to_string();
12911296

12921297
let join_clause = self.table.to_join_clause(
12931298
fkey,
@@ -1300,7 +1305,7 @@ impl NodeBuilder {
13001305
"
13011306
(
13021307
select
1303-
jsonb_build_object({object_clause})
1308+
{object_clause_string}
13041309
from
13051310
{quoted_schema}.{quoted_table} as {quoted_block_name}
13061311
where

0 commit comments

Comments
 (0)