I am trying to execute multiple queries in one table using the UNION rule
I have two tables:
- project (id, name, pinned BOOLEAN)
- skills (m2m for projects)
I want to first get an array of strings that have pinned set to true and populate the remaining last entries ( pinned set to false )
SELECT project.id AS project_id, project.name AS project_name, array_agg(json_build_object('skill_id', project_skills.id,'name', project_skills.skill)) AS skills from project LEFT OUTER JOIN project_skills on project.name = project_skills.project WHERE project.pinned = true GROUP BY project_id,project_name UNION SELECT project.id AS project_id, project.name AS project_name, array_agg(json_build_object('skill_id', project_skills.id,'name', project_skills.skill)) AS skills from project LEFT OUTER JOIN project_skills on project.name = project_skills.project WHERE project.id != 1 AND project.pinned = false GROUP BY project_id,project_name ORDER BY project.create_date DESC LIMIT 5
When I run this request, I get the following error
ERROR: could not identify an equality operator for type json[] LINE 7: array_agg(json_build_object('skill_id', project_skills.id,...
I do not understand this error. Is this unsuccessful due to an attempt to compare json columns from both results?
I am using Postgres 9.4.
json postgresql union
Kannaj
source share