is it relatively safe to union two tables with UUID PK? I want to union two tables whose primary keys are UUID(V4) and I want to preserve them in the result. I work with PostgreSQL

Is it safe to do this?
What are the pitfalls may be encountered?
I guess your concern is that the UUIDs could no longer be unique after the UNION.
That is of course theoretically possible, but the danger is no bigger that if you use version-4 UUIDs as primary keys.
In practice, you don't have to worry about that. Wikipedia describes it well:

with [...] random version-4 UUIDs, collisions can occur even without implementation problems, albeit with a probability so small that it can normally be ignored. This probability can be computed precisely based on analysis of the birthday problem.
For example, the number of random version-4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion, computed as follows:

This number is equivalent to generating 1 billion UUIDs per second for about 85 years. A file containing this many UUIDs, at 16 bytes per UUID, would be about 45 exabytes.

If you paranoid enough to be afraid of that, you shouldn't use version-4 UUIDs at all, but use a different, collision-free UUID algorithm like version 1 or 2.