Postgresql Union: Do not repeat based on 1 column only
full outer join is very handy for this as follows:
select id, case when users.id is null then 2 else 1 end as category
from users
full outer join users_2 using (id);

How this works is that the id column will be null if the row comes from users while it won't be null when it's coming from users_2.
Alternatively you can do it with union (and use union all because we're already using not exists to discard duplicates):
select id, 1 as category
from users
union all
select id, 2
from users_2 where not exists (select id from users where id = users_2.id);

but as you can see the query becomes much longer.
A third way that is even longer and probably even less efficient is to use distinct on:
select distinct on (id) id, category
from (
  select id, 1 as category
  from users
  union all
  select id, 2
  from users_2
) x
order by id, category;

NB This last query does guarantee the order in the output; the first two queries don't!
See https://dbfiddle.uk/?rdbms=postgres_13&amp;fiddle=dd8bdbc82edc26cce9e8ba9fdde84517