Drizzle failed to parse an empty JSONB Array

so I have a query that calls 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, I was able to confirm this by adding a 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
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server