select gaia2.source_id as dr2_source_id, gaia3.source_id as dr3_source_id,
distance(
point('', gaia3.ra_prop, gaia3.dec_prop),
point('', gaia2.ra, gaia2.dec)
) * 3600e3 as angular_distance,
gaia3.phot_g_mean_mag - gaia2.phot_g_mean_mag as magnitude_difference,
proper_motion_propagation
from (
select source_id,
ra + 1. / 3600e3 * coalesce(pmra, 0) * -0.5 / cos(radians(dec)) as ra_prop,
dec + 1. / 3600e3 * coalesce(pmdec, 0) * -0.5 as dec_prop,
to_boolean(to_integer(coalesce(parallax * 0 + 1, 0)))
as proper_motion_propagation,
phot_g_mean_mag
from edr3.gaia_source
where random_index between 0 and 99
offset 0
) as gaia3
join gaiadr2.gaia_source as gaia2
on 1 = contains(
point('', gaia3.ra_prop, gaia3.dec_prop),
circle('', gaia2.ra, gaia2.dec, 2. / 3600)
)