© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago
erikash

What is the best way to join with JSONB arrays with Drizzle?

Hi guys,
I'm trying to migrate the following query to Drizzle:
SELECT "mutzar"."misparzihuylakoach",
"mutzar"."sugmutzar",
"mutzar"."shemyatzran",
"heshbonopolisas" ->> 'MISPAR_POLISA_O_HESHBON'
FROM "mutzar"
LEFT JOIN Jsonb_array_elements("data" -> 'HeshbonotOPolisot' ->
'HeshbonOPolisa'
) AS
"heshbonOPolisas"
ON TRUE
WHERE "mutzar"."misparzihuylakoach" = $1 -- params: ["123123123"]

I've successfully migrated it to:
const result = await db
.select({
misparZihuyLakoach: mutzar.misparZihuyLakoach,
sugMutzar: mutzar.sugMutzar,
shemYatzran: mutzar.shemYatzran,
misparPolisaOHeshbon: sql
"heshbonOPolisas" ->> 'MISPAR_POLISA_O_HESHBON'
"heshbonOPolisas" ->> 'MISPAR_POLISA_O_HESHBON'
,
})
.from(mutzar)
.leftJoin(
sql
jsonb_array_elements("data"->'HeshbonotOPolisot'->'HeshbonOPolisa') as "heshbonOPolisas"
jsonb_array_elements("data"->'HeshbonotOPolisot'->'HeshbonOPolisa') as "heshbonOPolisas"
,
eq(sql
TRUE
TRUE
, sql
TRUE
TRUE
)
)
.where(eq(mutzar.misparZihuyLakoach, '123123123'));


I've tried following the docs and using const heshbonOPolisas = alias(sqljsonb_array_elements("data"->'HeshbonotOPolisot'->'HeshbonOPolisa'), "heshbonOPolisa") but got a type error

What is the best way to join with JSONB arrays with Drizzle?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Best way to query jsonb field
Drizzle TeamDTDrizzle Team / help
3y ago
Updating jsonb objects with Drizzle?
Drizzle TeamDTDrizzle Team / help
3y ago
help with drizzle-zod with jsonb column
Drizzle TeamDTDrizzle Team / help
3y ago
What is the best way to handle Query Errors?
Drizzle TeamDTDrizzle Team / help
9mo ago