Unnest ids from arrays based on priority with no duplication Here is the sample schema for my database:
Priority  | Productive | UnProductive | Neutral |
-------------------------------------------------
  High    |   [1, 2]   |      []      |  [4, 5] |
  Medium  |   [3, 4]   |    [5, 7]    |   [2]   |
  Low     |     [1]    |    [2, 6]    |    []   |

NOTE: These numbers are actually UUIDs in my database and no numbers will be repeated in the same row.
I want to unnest the category from productive, unproductive and neutral such that:

Not any from 1 to 7 numbers are repeated and
If the number is already captured by High Priority it will not be captured by Medium and same goes for Low.

Expected output:
Productive: [1, 2, 3]  # no 4 because it have been captured by neutral High priority
UnProductive: [7, 6]  # no 5 and 2 because it have been captured before
Neutral: [4, 5]  # no 2 because it is caputed before
I've solved this relationaly by unnesting and assigning the weights as suggested by @Akina.
with weighted as (
  select
    case priority
      when 'High' then 6
      when 'Medium' then 3
      when 'Low' then 0
    end as priority,
    productive,
    unproductive,
    neutral
  from
    data
), unnested as (
  select
    unnest(productive) as id, priority, 2 as category 
  from
    weighted
  union all
  select
    unnest(unproductive) as id, priority, 1 as category 
  from
    weighted
  union all
  select
    unnest(neutral) as id, priority, 0 as category
  from
    weighted
) 
select
  case category
    when 0 then 'Neutral'
    when 1 then 'UnProductive'
    when 2 then 'Productive'
  end,
  array_agg(id)
from unnested x
where not exists (
  select null
  from unnested
  where id = x.id
  and priority + category &gt; x.priority + x.category
)
group by category, 1
order by category desc;

See https://dbfiddle.uk/?rdbms=postgres_13&amp;fiddle=8a54e1f8018c49146faba3e446f7b694
It can probably be done more efficiently.