o.id, o.org_no, o.org_name, o.channel_slug, o.applicant_contact_id, o.mj_contact_id, o.itn_contact_id, o.lawyer_contact_id, o.lawyer_assigned_date, o.channel_id_mj, o.channel_id_law, o.stage, ac.id as applicant_id, ac.category as applicant_category, ac.name as applicant_name, ac.affiliation as applicant_affiliation, ac.dept_name as applicant_dept_name, ac.title as applicant_title, ac.phone as applicant_phone, ac.email as applicant_email, mc.id as mj_c_id, mc.category as mj_c_category, mc.name as mj_c_name, mc.affiliation as mj_c_affiliation, mc.dept_name as mj_c_dept_name, mc.title as mj_c_title, mc.phone as mj_c_phone, mc.email as mj_c_email, ic.id as itn_c_id, ic.category as itn_c_category, ic.name as itn_c_name, ic.affiliation as itn_c_affiliation, ic.dept_name as itn_c_dept_name, ic.title as itn_c_title, ic.phone as itn_c_phone, ic.email as itn_c_email, lc.id as lawyer_c_id, lc.category as lawyer_c_category, lc.name as lawyer_c_name, lc.affiliation as lawyer_c_affiliation, lc.dept_name as lawyer_c_dept_name, lc.title as lawyer_c_title, lc.phone as lawyer_c_phone, lc.email as lawyer_c_email from organization o left join contact ac on ac.id = o.applicant_contact_id left join contact mc on mc.id = o.mj_contact_id left join contact ic on ic.id = o.itn_contact_id left join contact lc on lc.id = o.lawyer_contact_id insert into organization (org_no, org_name, channel_slug) values (#{orgNo}, #{orgName}, #{channelSlug}) on conflict (org_no, org_name) do update set channel_slug = excluded.channel_slug, updated_at = now() update organization set applicant_contact_id = #{applicantContactId}, mj_contact_id = #{mjContactId}, itn_contact_id = #{itnContactId}, lawyer_contact_id = #{lawyerContactId}, lawyer_assigned_date = #{lawyerAssignedDate}, updated_at = now() where id = #{id} update organization set channel_id_mj = #{channelId}, updated_at = now() where id = #{id} update organization set channel_id_law = #{channelId}, updated_at = now() where id = #{id} update organization set stage = #{stage}, updated_at = now() where id = #{id} update organization set channel_id_mj = null, channel_id_law = null, stage = null, updated_at = now() where id = #{id}