{
  "db_name": "PostgreSQL",
  "query": "SELECT jsonb_build_object(\n                'kind', jb.kind,\n                'script_path', jb.runnable_path,\n                'latest_schema', COALESCE(\n                    (SELECT DISTINCT ON (s.path) s.schema FROM script s WHERE s.workspace_id = $1 AND s.path = jb.runnable_path AND jb.kind = 'script' ORDER BY s.path, s.created_at DESC),\n                    (SELECT flow_version.schema FROM flow LEFT JOIN flow_version ON flow_version.id = flow.versions[array_upper(flow.versions, 1)] WHERE flow.workspace_id = $1 AND flow.path = jb.runnable_path AND jb.kind = 'flow')\n                ),\n                'schemas', ARRAY(\n                    SELECT jsonb_build_object(\n                        'script_hash', LPAD(TO_HEX(COALESCE(s.hash, f.id)), 16, '0'),\n                        'job_ids', ARRAY_AGG(DISTINCT j.id),\n                        'schema', (ARRAY_AGG(COALESCE(s.schema, f.schema)))[1]\n                    ) FROM v2_job j\n                    LEFT JOIN script s ON s.hash = j.runnable_id AND j.kind = 'script'\n                    LEFT JOIN flow_version f ON f.id = j.runnable_id AND j.kind = 'flow'\n                    WHERE j.id = ANY(ARRAY_AGG(jb.id))\n                    GROUP BY COALESCE(s.hash, f.id)\n                )\n            ) FROM v2_job jb\n            WHERE (jb.kind = 'flow' OR jb.kind = 'script')\n                AND jb.workspace_id = $1 AND jb.id = ANY($2)\n            GROUP BY jb.kind, jb.runnable_path",
  "describe": {
    "columns": [
      {
        "ordinal": 0,
        "name": "jsonb_build_object",
        "type_info": "Jsonb"
      }
    ],
    "parameters": {
      "Left": [
        "Text",
        "UuidArray"
      ]
    },
    "nullable": [
      null
    ]
  },
  "hash": "0c89ef278782f5a72b0b07ab3ba0edc487f03edd61936fcf77dee93fb22839ea"
}
