© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
khsrhmmnn

Drizzle failed to parse an empty JSONB Array

so I have a query that calls
ARRAY_AGG()
ARRAY_AGG()
function and the result of query returned the aggregated value

since the aggregated column is a JSONB this results in Array of JSONB, but some of the row may return an empty json,

id|jsonb_array_col                    |
1 | {{"a":"a","b":2},{"a":"a","b":2}} | 
2 | {}                                |
id|jsonb_array_col                    |
1 | {{"a":"a","b":2},{"a":"a","b":2}} | 
2 | {}                                |


this is the query for the selector
{
  logs: sql<z.infer<typeof RoomDurationMeta>[]>`COALESCE(ARRAY_AGG(meta ORDER BY ${activitiesLog.meta} ->> 'joinTime'), '{}'::jsonb[] )
            `.as('logs')
}
{
  logs: sql<z.infer<typeof RoomDurationMeta>[]>`COALESCE(ARRAY_AGG(meta ORDER BY ${activitiesLog.meta} ->> 'joinTime'), '{}'::jsonb[] )
            `.as('logs')
}


however due to the particular empty array i got an error
SyntaxError: Unexpected token N in JSON at position 0
SyntaxError: Unexpected token N in JSON at position 0
, I was able to confirm this by adding a
limit(1)
limit(1)
to the query

by limiting the query which only return 1 row
id|jsonb_array_col                    |
1 | {{"a":"a","b":2},{"a":"a","b":2}} | 
id|jsonb_array_col                    |
1 | {{"a":"a","b":2},{"a":"a","b":2}} | 


the query was performed sucesfully
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

How to Access an array of strings in jsonb format
Drizzle TeamDTDrizzle Team / help
3y ago
Updating jsonb objects with Drizzle?
Drizzle TeamDTDrizzle Team / help
3y ago
Empty default array
Drizzle TeamDTDrizzle Team / help
2y ago
How to create jsonb attribute index in drizzle
Drizzle TeamDTDrizzle Team / help
3y ago