select av.address_validation_public_id
       , i.identity_public_id
       , a.address_public_id
       , a.type
       , a.value
       , a.created_at
       , av.method
       , av.token_hash
       , av.code_hash
       , av.attempts
       , av.created_at
       , av.expires_at
       , av.revoked_at
       , av.validated_at
from address_validation av
join address            a  using(address_id)
left join identity      i  using(identity_id)
where (($1 is null) or (address_validation_public_id = $1));
