SELECT_SQL = "\nselect\n thread_id,\n checkpoint,\n checkpoint_ns,\n checkpoint_id,\n parent_checkpoint_id,\n metadata,\n (
\n select array_agg(array[bl.channel::bytea, bl.type::bytea, bl.blob])\n from jsonb_each_text(checkpoint -> 'channel_versions')\n inner join checkpoint_blobs bl\n on bl.thread_id = checkpoints.thread_id\n and bl.checkpoint_ns = checkpoints.checkpoint_ns\n and bl.channel = jsonb_each_text.key\n and bl.version = jsonb_each_text.value\n ) as channel_values,\n (\n select\n array_agg(array[cw.task_id::text::bytea, cw.channel::bytea, cw.type::bytea, cw.blob] order by cw.task_id,
cw.idx)\n from checkpoint_writes cw\n where cw.thread_id = checkpoints.thread_id\n and cw.checkpoint_ns = checkpoints.checkpoint_ns\n and cw.checkpoint_id = checkpoints.checkpoint_id\n
) as pending_writes\nfrom checkpoints "