DEV Community

Bharathim31
Bharathim31

Posted on

How to write a json in middle of union functionality throwing error

I wrote a union function in the middle of union wrote a json object is one of the parameter, but throwing error : could not identify an equality operator for type json. Here is my code. select(SELECT array_to_json(array_agg(row_to_json(resdt))) FROM (select vt.task_id,vp.project_name,vp.status as project_status, vt.project_id,vt.task_description,vt.planned_start_date,vt.planned_end_date, (select array_to_json(array_agg(row_to_json(b))) FROM (select vl.* from public."VOfficeApp_task" vat inner join public."VOfficeApp_task_labels" vtl on vat.task_id = vtl.task_id inner join public."VOfficeApp_labels" vl on vl.label_id = vtl.label_id where vl.status = true and vat.task_id = vt.task_id )b)as label_name, (select array_to_json(array_agg(row_to_json(b))) FROM (select tr.task_resource_id,tr.task_id,tr.project_resource_id , tr.assigned_date,tr.assigned_by,pr.employee_id as id, concat(u.first_name,u.last_name) as employeename from public."VOfficeApp_task" vtr inner join public."VOfficeApp_project_resources" pr on pr.project_id = vtr.project_id inner join public."VOfficeApp_task_resource" tr on tr.project_resource_id = pr.project_resource_id and tr.task_id = vt.task_id inner join public."VOfficeApp_user" u on u.id =pr.employee_id where tr.released_date is null and vtr.task_id =vt.task_id and vtr.status != 'Delete')b)as user_name, (select count(task_id)from public."VOfficeApp_task" ptra where ptra.task_id = vt.task_id and status = 'Assigned')Active_count, from public."VOfficeApp_task" vt inner join public."VOfficeApp_projects" vp on vt.project_id = vp.project_id inner join public."VOfficeApp_task_resource" vtr on vt.task_id = vtr.task_id inner join public."VOfficeApp_project_resources" vpr on vtr.project_resource_id = vpr.project_resource_id left join public."VOfficeApp_conversation" cvv on cvv.projtaskid = vt.task_id where vp.company_id = companyid and vp.created_by = createdby and vt.status != 'Delete' --order by vt.task_id desc union select vt.task_id,vp.project_name,vp.status as project_status, vt.project_id,vt.task_description,vt.planned_start_date,vt.planned_end_date, (select array_to_json(array_agg(row_to_json(b))) FROM (select vl.* from public."VOfficeApp_task" vat inner join public."VOfficeApp_task_labels" vtl on vat.task_id = vtl.task_id inner join public."VOfficeApp_labels" vl on vl.label_id = vtl.label_id where vl.status = true and vat.task_id = vt.task_id )b)as label_name, (select array_to_json(array_agg(row_to_json(b))) FROM (select tr.task_resource_id,tr.task_id,tr.project_resource_id , tr.assigned_date,tr.assigned_by,pr.employee_id as id, concat(u.first_name,u.last_name) as employeename from public."VOfficeApp_task" vtr inner join public."VOfficeApp_project_resources" pr on pr.project_id = vtr.project_id inner join public."VOfficeApp_task_resource" tr on tr.project_resource_id = pr.project_resource_id and tr.task_id = vt.task_id inner join public."VOfficeApp_user" u on u.id =pr.employee_id where tr.released_date is null and vtr.task_id =vt.task_id and vtr.status != 'Delete')b)as user_name, from public."VOfficeApp_task" vt inner join public."VOfficeApp_projects" vp on vt.project_id = vp.project_id inner join public."VOfficeApp_task_resource" vtr on vt.task_id = vtr.task_id inner join public."VOfficeApp_project_resources" vpr on vtr.project_resource_id = vpr.project_resource_id --inner join public."VOfficeApp_user" u on u.id =vpr.employee_id where vp.company_id = companyid and vpr.employee_id = createdby and vt.status != 'Delete' --order by vt.task_id desc )resdt)as My_tasks;

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay